Jump to content
madrussian

Faster alternatives to isKindOf?

Recommended Posts

So... I have an array of obj types, and I want to remove all elements for which the obj type is a man.

 

For my particular application (building path-finder), this bit of code needs to be fully optimized.  In other words, every little nano-second counts!  My code currently looks something like this:

_objTypes = _objTypes select {
    ! ((typeOf _x) isKindOf "Man")
};

Any way to make this run much faster?  Specifically with any of the newer A3 scripting commands?

 

(Btw - Seems most soldier types have a lengthy parent hierarchy, so that's what got me thinking so hard on this.)  Thanks!

 

Share this post


Link to post
Share on other sites

besides caching the isKindOf result, which I'm not sure if its faster. No.

  • Like 1

Share this post


Link to post
Share on other sites

Iskindof is pretty damn fast. You aren't going to optimise that line of code any more.

  • Like 1

Share this post


Link to post
Share on other sites

can't you use:

 

_x isKindOf "Man"

 

instead

  • Like 1

Share this post


Link to post
Share on other sites

@gc8 Correct, good catch.

 

Thanks guys, ok isKindOf it is then!

Share this post


Link to post
Share on other sites
1 hour ago, Tankbuster said:

He wants all objects that aren't man.

 

I think @gc8 was pointing out that I could potentially optimize that code slightly by losing the typeOf command.  As in, isKindOf will take a string or an obj (as 1st parameter).  So if I had an array of objs (instead of types), the code might look something like:

_objs = _objs select {
    ! (_x isKindOf "Man")
};

 

Edit:

And actually my original code (where I had obj types) wasn't quite right, should be:

_objTypes = _objTypes select {
    ! (_x isKindOf "Man")
};

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×