[geos-devel] Judicous Inlining
Norman Vine
nhv at cape.com
Mon Feb 17 12:34:37 EST 2003
Hi All
After looking at the code some more
I think we want a few inline methods
class CoordinateList {
public:
Coordinate& rawGetAt(int pos){
return (*vect)[pos];
}
}
and a
class PointCoordinateList : public CoordinateList {
public:
Coordinate& rawGetAt(int pos){
point_3d pt;
pt=(*vect)[pos];
return *(new Coordinate(pt.x,pt.y,pt.z));
}
}
for those cases where we *know* we are making an 'inbounds' getAt() call.
AFAICT this is the *majority* of the cases.
FWIW
With this and inlining most of the Coordinate class
TestSweepLineSpeed execution time drops from
n Pts: 1024000 Executed in 26518 ms.
to
n Pts: 1024000 Executed in 21210 ms.
a 20% improvement
and coupled with CFLAGS=-O3 -fomit-frame-pointer
18500ms or a 30% improvement
Cheers
Norman
class Coordinate {
public:
static Coordinate getNull() {
return
Coordinate(DoubleNotANumber,DoubleNotANumber,DoubleNotANumber);
}
Coordinate() {
x=0.0;
y=0.0;
z=DoubleNotANumber;
}
Coordinate(double xNew, double yNew, double zNew) {
x=xNew;
y=yNew;
z=zNew;
}
Coordinate(const Coordinate &c){
x=c.x;
y=c.y;
z=c.z;
}
Coordinate(double xNew, double yNew){
x=xNew;
y=yNew;
z=DoubleNotANumber;
}
void setNull() {
x=DoubleNotANumber;
y=DoubleNotANumber;
z=DoubleNotANumber;
}
void setCoordinate(Coordinate other) {
x = other.x;
y = other.y;
z = other.z;
}
bool equals2D(Coordinate other) {
return (x == other.x && y == other.y);
}
int compareTo(Coordinate other);
bool equals3D(Coordinate other);
string toString();
void makePrecise();
double distance(Coordinate p) {
double dx = x - p.x;
double dy = y - p.y;
return sqrt(dx * dx + dy * dy);
}
double x; /// x-coordinate
double y; /// y-coordinate
double z; /// z-coordinate
};
More information about the geos-devel
mailing list