Static C / C Object Performance

Here is the method from the class in some Apple sample code example . Why is this method defined as a static C method, and not an Objective C class method or a class method? In the context in which it is used, I believe that it should be as realistic as possible. That's why? Is this the most efficient way to declare a method?

static BOOL lineIntersectsRect(MKMapPoint p0, MKMapPoint p1, MKMapRect r) { //Do stuff return MKMapRectIntersectsRect(r, r2); } 
+4
source share
2 answers

This is not a static method, but rather a function. And it is probably defined as a function because it works with two data types ( MKMapPoint and MKMapRect ) that are not objects (they are C-structures) and therefore cannot have methods associated with them.

+6
source
Functions

C is faster than Objective-C methods, because C functions bypass Objective-C's messaging system. The static in the declaration limits the visibility of the function for the current compilation unit, so it is visible only in this particular file. The compiler can take a hint using the static to optimize assembler output for this function, so you can increase performance.

+2
source

Source: https://habr.com/ru/post/1383977/


All Articles