[geos-devel] gprof (missing attachment)

strk at refractions.net strk at refractions.net
Sun Feb 6 07:28:30 EST 2005


Sorry, I didn't specify that, the function is this, already
optimized:

bool
Envelope::intersects(const Envelope* other) const
{
        // Optimized to reduce function calls
        if ( isnull ) return false;
        return !(other->minx > maxx ||
                         other->maxx < minx ||
                         other->miny > maxy ||
                         other->maxy < miny);
}

Note that isnull is a bool, original code called ::isNull, a step
after I've inlined it using maxx<minx || maxy<miny. Currenlty it
is a single bool check.
Maybe the return !(expr) is not optimized by the compiler, but I'm 
not sure at that would be simple.... first expression evaluating
to false should prevent further checkings. Am I wrong ?

Inlining it should have some benefits as the function is invoked
269666299 times (for buffer2000).

--strk;

On Sun, Feb 06, 2005 at 07:02:05AM -0500, Norman Vine wrote:
> If this is actually a hotspot probably best to take advantage
> of all the apriori knowledge we can :-)
> 
> < I think this is correct some one should check my logic though >
> 
> bool Envelope::intersects(const Coordinate& p1,const Coordinate& p2,const Coordinate& q1,const Coordinate& q2)
> {
> /* please leave this commented code as documentation 
>     if( min(p1.x,p2.x) > max(q1.x,q2.x) ||
>           max(p1.x,p2.x) < min(q1.x,q2.x) ||
>           min(p1.y,p2.y) > max(q1.y,q2.y) ||
>           max(p1.y,p2.y) < min(q1.y,q2.y) )
>         return false;
>     return true;
> */
> 
>     if( p1.x < p2.x )  {
>         if( q1.x > q2.x )  {
>             if( p1.x > q1.x )  return false;
>             if( p2.x < q2.x )  return false;
>         } else {
>             if( p1.x > q2.x )  return false;
>             if( p2.x < q1.x )  return false;
>         }
>     } else {
>         if( q1.x > q2.x )  {
>             if( p2.x > q1.x )  return false;
>             if( p1.x < q2.x )  return false;
>         } else {
>             if( p2.x > q2.x )  return false;
>             if( p1.x < q1.x )  return false;
>         }
>     }
> 
>     if( p1.y < p2.y ) {
>         if( q1.y > q2.y )  {
>             if( p1.y > q1.y )  return false;
>             if( p2.y < q2.y )  return false;
>         } else {
>             if( p1.y > q2.y )  return false;
>             if( p2.y < q1.y )  return false;
>         }
>     } else {
>         if( q1.y > q2.y ) {
>             if( p2.y > q1.y )  return false;
>             if( p1.y < q2.y )  return false;
>         } else {
>             if( p2.y > q2.y )  return false;
>             if( p1.y < q1.y )  return false;
>         }
>     }
>     return true;
> }
> 
> _______________________________________________
> geos-devel mailing list
> geos-devel at geos.refractions.net
> http://geos.refractions.net/mailman/listinfo/geos-devel



More information about the geos-devel mailing list