Re: reduce redundant code

Tech-Archive recommends: Speed Up your PC by fixing your registry




"Larry Serflaten" <serflaten@xxxxxxxxxxxxxx> wrote in message
news:ORgyv8FhIHA.5088@xxxxxxxxxxxxxxxxxxxxxxx

"MP" <NoSpam@xxxxxxxxxx> wrote

I have to loop through the whole bag to see if it's A B or C in order to
put
it *into* my collection in the first place.
snip
seems better to just loop once???

The point was to identify code where you are testing for the same
object types (eg: A, B, and C) and load that group into a collection
once at the start of your application, or upon loading a new file,
or whatever the trigger is for the API to create its objects. Once
done you need not re-load the collection again for all those places
that used tests for those types.

Yes, you'd have loop through the bag to build the group collections,
but from then on, type testing would not be used within those loops
that used a grouped collection.

LFS


Ok I see what you were thinking of.
How this works in this case is
For Each File In Folder
For Each Obj In File
'check obj
Next
Next

so the collection(bag) is only accessed once
but, yes if the file were open for some time and various operations
performed on the collections at different points, then yes, I'd save a
collection and reuse it.
Thanks for your insights
Mark


.



Relevant Pages

  • Re: reduce redundant code
    ... looping through the api collection is "time-expensive" ... Otherwise I have to loop through once to collect all A,B and C into "my" ... For Each obj in Bag ... Yes, you'd have loop through the bag to build the group collections, ...
    (microsoft.public.vb.general.discussion)
  • Re: OO in Python? ^^
    ... >> def foo: ... >> obj = D1 ... > polymorphism. ... to which you can assign different object types (D ...
    (comp.lang.python)