[geos-commits] [SCM] GEOS branch svn-3.6 updated. a9066f5806965b58a021c3495c2479e2ecc026e1
git at osgeo.org
git at osgeo.org
Fri Sep 13 10:05:52 PDT 2019
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".
The branch, svn-3.6 has been updated
via a9066f5806965b58a021c3495c2479e2ecc026e1 (commit)
from b0bff6d07e559833ea5521e9a98216a558611e71 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit a9066f5806965b58a021c3495c2479e2ecc026e1
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Fri Sep 13 10:05:36 2019 -0700
Use std::array instead of std::vector in TopologyLocation.cpp
diff --git a/NEWS b/NEWS
index e73767e..4eedeb7 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Changes in 3.6.4
- Invalid union result from valid polygon inputs (#838)
- Static library does not contain C API (#878)
- Prevent crash when querying empty STRtree (#730)
+ - Overlay performance improvement (Paul Ramsey)
Changes in 3.6.3
diff --git a/include/geos/geomgraph/TopologyLocation.h b/include/geos/geomgraph/TopologyLocation.h
index 9b1fcd0..f0b5f8d 100644
--- a/include/geos/geomgraph/TopologyLocation.h
+++ b/include/geos/geomgraph/TopologyLocation.h
@@ -25,6 +25,7 @@
#include <geos/inline.h>
#include <vector>
+#include <array>
#include <string>
#ifdef _MSC_VER
@@ -65,8 +66,6 @@ public:
~TopologyLocation();
- TopologyLocation(const std::vector<int> &newLocation);
-
/** \brief
* Constructs a TopologyLocation specifying how points on, to the
* left of, and to the right of some GraphComponent relate to some
@@ -115,7 +114,7 @@ public:
void setLocation(int locValue);
/// Warning: returns reference to owned memory
- const std::vector<int> &getLocations() const;
+ const std::array<int, 3>& getLocations() const;
void setLocations(int on, int left, int right);
@@ -131,7 +130,8 @@ public:
private:
- std::vector<int> location;
+ std::array<int, 3> location;
+ std::size_t locationSize;
};
std::ostream& operator<< (std::ostream&, const TopologyLocation&);
diff --git a/src/geomgraph/TopologyLocation.cpp b/src/geomgraph/TopologyLocation.cpp
index 175fcbd..873ccb2 100644
--- a/src/geomgraph/TopologyLocation.cpp
+++ b/src/geomgraph/TopologyLocation.cpp
@@ -26,17 +26,11 @@
#include <iostream>
#include <cassert>
-using namespace std;
using namespace geos::geom;
namespace geos {
namespace geomgraph { // geos.geomgraph
-/*public*/
-TopologyLocation::TopologyLocation(const vector<int> &newLocation):
- location(newLocation.size(), Location::UNDEF)
-{
-}
/*public*/
TopologyLocation::TopologyLocation()
@@ -50,7 +44,7 @@ TopologyLocation::~TopologyLocation()
/*public*/
TopologyLocation::TopologyLocation(int on, int left, int right):
- location(3)
+ locationSize(3)
{
location[Position::ON]=on;
location[Position::LEFT]=left;
@@ -59,15 +53,17 @@ TopologyLocation::TopologyLocation(int on, int left, int right):
/*public*/
TopologyLocation::TopologyLocation(int on):
- location(1, on)
+ locationSize(1)
{
- //(*location)[Position::ON]=on;
+ location.fill(Location::UNDEF);
+ location[Position::ON] = on;
}
/*public*/
TopologyLocation::TopologyLocation(const TopologyLocation &gl)
:
- location(gl.location)
+ location(gl.location),
+ locationSize(gl.locationSize)
{
}
@@ -76,6 +72,7 @@ TopologyLocation&
TopologyLocation::operator= (const TopologyLocation &gl)
{
location = gl.location;
+ locationSize = gl.locationSize;
return *this;
}
@@ -84,7 +81,7 @@ int
TopologyLocation::get(size_t posIndex) const
{
// should be an assert() instead ?
- if (posIndex<location.size()) return location[posIndex];
+ if (posIndex<locationSize) return location[posIndex];
return Location::UNDEF;
}
@@ -92,7 +89,7 @@ TopologyLocation::get(size_t posIndex) const
bool
TopologyLocation::isNull() const
{
- for (size_t i=0, sz=location.size(); i<sz; ++i) {
+ for (size_t i=0; i<locationSize; ++i) {
if (location[i]!=Location::UNDEF) return false;
}
return true;
@@ -102,7 +99,7 @@ TopologyLocation::isNull() const
bool
TopologyLocation::isAnyNull() const
{
- for (size_t i=0, sz=location.size(); i<sz; ++i) {
+ for (size_t i=0; i<locationSize; ++i) {
if (location[i]==Location::UNDEF) return true;
}
return false;
@@ -119,21 +116,21 @@ TopologyLocation::isEqualOnSide(const TopologyLocation &le, int locIndex) const
bool
TopologyLocation::isArea() const
{
- return location.size()>1;
+ return locationSize>1;
}
/*public*/
bool
TopologyLocation::isLine() const
{
- return location.size()==1;
+ return locationSize==1;
}
/*public*/
void
TopologyLocation::flip()
{
- if (location.size()<=1) return;
+ if (locationSize<=1) return;
int temp=location[Position::LEFT];
location[Position::LEFT]=location[Position::RIGHT];
location[Position::RIGHT] = temp;
@@ -143,16 +140,14 @@ TopologyLocation::flip()
void
TopologyLocation::setAllLocations(int locValue)
{
- for (size_t i=0, sz=location.size(); i<sz; ++i) {
- location[i]=locValue;
- }
+ location.fill(locValue);
}
/*public*/
void
TopologyLocation::setAllLocationsIfNull(int locValue)
{
- for (size_t i=0, sz=location.size(); i<sz; ++i) {
+ for (size_t i=0; i<locationSize; ++i) {
if (location[i]==Location::UNDEF) location[i]=locValue;
}
}
@@ -172,7 +167,7 @@ TopologyLocation::setLocation(int locValue)
}
/*public*/
-const vector<int> &
+const std::array<int, 3>&
TopologyLocation::getLocations() const
{
return location;
@@ -182,7 +177,7 @@ TopologyLocation::getLocations() const
void
TopologyLocation::setLocations(int on, int left, int right)
{
- assert(location.size() >= 3);
+ assert(locationSize >= 3);
location[Position::ON]=on;
location[Position::LEFT]=left;
location[Position::RIGHT]=right;
@@ -192,7 +187,7 @@ TopologyLocation::setLocations(int on, int left, int right)
bool
TopologyLocation::allPositionsEqual(int loc) const
{
- for (size_t i=0, sz=location.size(); i<sz; ++i) {
+ for (size_t i=0; i<locationSize; ++i) {
if (location[i]!=loc) return false;
}
return true;
@@ -203,32 +198,32 @@ void
TopologyLocation::merge(const TopologyLocation &gl)
{
// if the src is an Area label & and the dest is not, increase the dest to be an Area
- size_t sz=location.size();
- size_t glsz=gl.location.size();
+ size_t sz=locationSize;
+ size_t glsz=gl.locationSize;
if (glsz>sz) {
- location.resize(3);
+ locationSize = 3;
location[Position::LEFT]=Location::UNDEF;
location[Position::RIGHT]=Location::UNDEF;
}
- for (size_t i=0; i<sz; ++i) {
+ for (size_t i=0; i<locationSize; ++i) {
if (location[i]==Location::UNDEF && i<glsz)
location[i]=gl.location[i];
}
}
-string
+std::string
TopologyLocation::toString() const
{
- stringstream ss;
+ std::stringstream ss;
ss << *this;
return ss.str();
}
std::ostream& operator<< (std::ostream& os, const TopologyLocation& tl)
{
- if (tl.location.size()>1) os << Location::toLocationSymbol(tl.location[Position::LEFT]);
+ if (tl.locationSize>1) os << Location::toLocationSymbol(tl.location[Position::LEFT]);
os << Location::toLocationSymbol(tl.location[Position::ON]);
- if (tl.location.size()>1) os << Location::toLocationSymbol(tl.location[Position::RIGHT]);
+ if (tl.locationSize>1) os << Location::toLocationSymbol(tl.location[Position::RIGHT]);
return os;
}
-----------------------------------------------------------------------
Summary of changes:
NEWS | 1 +
include/geos/geomgraph/TopologyLocation.h | 8 ++---
src/geomgraph/TopologyLocation.cpp | 57 ++++++++++++++-----------------
3 files changed, 31 insertions(+), 35 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list