logo       

AutoCompMethodBrowser: msg#00228

audio.supercollider.devel

Subject: AutoCompMethodBrowser

<x-tad-smaller> </x-tad-smaller><x-tad-smaller>classvar</x-tad-smaller><x-tad-smaller> methDict; </x-tad-smaller><x-tad-smaller>// note, not the same as Class-methods</x-tad-smaller><x-tad-smaller>
</x-tad-smaller><x-tad-smaller>// this is a dictionary: selector -> [method, method, method...]</x-tad-smaller><x-tad-smaller>
</x-tad-smaller><x-tad-smaller>// with this, I can look up method selectors almost instantly</x-tad-smaller><x-tad-smaller>
</x-tad-smaller><x-tad-smaller>// otherwise, every time I would have to search the whole class tree (slow)</x-tad-smaller><x-tad-smaller>

*initClass {
methDict = </x-tad-smaller><x-tad-smaller>IdentityDictionary</x-tad-smaller><x-tad-smaller>.new;
</x-tad-smaller><x-tad-smaller>Class</x-tad-smaller><x-tad-smaller>.allClasses.do({ </x-tad-smaller><x-tad-smaller>|class|</x-tad-smaller><x-tad-smaller>
class.methods.do({ </x-tad-smaller><x-tad-smaller>|meth|</x-tad-smaller><x-tad-smaller>
</x-tad-smaller><x-tad-smaller>// if this selector hasn't been initialized, make a new set</x-tad-smaller><x-tad-smaller>
methDict[meth.name].isNil.if({ methDict.put(meth.name, </x-tad-smaller><x-tad-smaller>Set</x-tad-smaller><x-tad-smaller>.new); });
methDict[meth.name].add(meth);
});
});
methodExclusions = [];
}

This is really wasteful. It creates a huge directory, most of which is never used. It should be done as needed.
To do it each time it is needed is not so slow. The code below runs in 40 milliseconds on my machine.
Perhaps a primitive that returns the methods for a selector would help here if speed is really a problem.
Why is the Set not an IdentitySet?
All those objects make the GC take longer to complete a cycle resulting in more garbage generated before a collection. Larger working sets also make cache performance worse.

(
var methods, selector;
selector = \value;
bench {
methods = [];
Class.allClasses.do({ |class|
class.methods.do({ |meth|
if (meth.name == selector) {
methods = methods.add(meth);
}
});
});
};
methods.postln;
)
</x-tad-smaller>
_______________________________________________
sc-dev mailing list
sc-dev-Ayv8T2snMLBt9CRQqspbbg@xxxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-dev
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise