2015-10-01 11:18 GMT+02:00 Henrik Nergaard <[email protected]>:

> Hi,
>
> Is there a simple way to query a variable to check how many methods that
> access it? (just want to know the size)
>
> This works, but it is quite slow.
> (Morph whichSelectorsAccess: #owner) size
> Morph withAllSubclasses inject: 0 into: [ :sum :class | sum + (class
> whichSelectorsAccess: #owner) size ]
>
> <http://forum.world.st/file/n4852956/aMenuMorph%28885522432%29.png>
>
> Best regards,
> Henrik
>


I don't think there is a fast way.
But you can try to work with the methods AST. (but...see below)

b := Bag new.
Morph methodsDo:[:m | (m ast allChildren select:[:n | n isVariable and:[n
isInstance]])  asSet do:[:e | b add: e name]].
b valuesAndCounts
"-->   a Dictionary(#bounds->39 #color->10 #extension->37 #fullBounds->14
#owner->53 #submorphs->50 )"

This does not distinguish between read and write access for variables.
This is slow if the AST is not in the ASTCache, pretty fast if it is.

But if you use something like "withAllSubclasses do:... with all methods
... method ast"
this will fillup the ASTCache pretty fast. And an image with ast nodes for
every compiled method is about ~300-400MB large.






>
>
>
> --
> View this message in context:
> http://forum.world.st/Querying-the-accessors-of-a-variable-tp4852956.html
> Sent from the Pharo Smalltalk Developers mailing list archive at
> Nabble.com.
>
>

Reply via email to