• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Is this the correct way to cache an IMP?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is this the correct way to cache an IMP?


  • Subject: Is this the correct way to cache an IMP?
  • From: Graham Cox <email@hidden>
  • Date: Thu, 5 Aug 2010 22:59:50 +1000

I have a Obj-C method that is highly recursive, and needs to run at maximum performance. With this in mind, I am locally caching the method's own IMP to avoid the message dispatch for the recursive calls. It seems to work and gives a measurable benefit, but I need to be absolutely certain it's right before committing it to a release. Can anyone comment on whether it actually is right? Have I missed anything? Anything even faster?


#define qUseImpCaching		1


- (void)  recursivelySearchWithRect:(NSRect) rect index:(NSUInteger) indx
{
#if qUseImpCaching
	static void(*sfunc)( id, SEL, NSRect, NSUInteger ) = nil;

	if ( sfunc == nil )
		sfunc = (void(*)( id, SEL, NSRect, NSUInteger ))[[self class] instanceMethodForSelector:_cmd];
#endif

// other code omitted
// recurse:

	#if qUseImpCaching
		sfunc( self, _cmd, rect, subnode );
	#else
		[self recursivelySearchWithRect:rect index:subnode];
	#endif
}


--Graham_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Is this the correct way to cache an IMP?
      • From: Ken Thomases <email@hidden>
    • Re: Is this the correct way to cache an IMP?
      • From: Jean-Daniel Dupas <email@hidden>
  • Prev by Date: Re: [Q] Enter Key & HIG
  • Next by Date: Re: Is this the correct way to cache an IMP?
  • Previous by thread: Re: MKMapView
  • Next by thread: Re: Is this the correct way to cache an IMP?
  • Index(es):
    • Date
    • Thread