Skip to content

Commit 1af909a

Browse files
Cache rewriting fix (#9)
1 parent e15f666 commit 1af909a

File tree

8 files changed

+37
-22
lines changed

8 files changed

+37
-22
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ file( GLOB_RECURSE IFC_HEADERS include/ifcpp/Ifc *.h )
1212
file( GLOB_RECURSE IFC_SOURCES src/Ifc *.cpp )
1313

1414
set( SOURCES
15-
src/Model/AttributeObject.cpp
1615
src/Model/BuildingGuid.cpp
1716
src/Model/BuildingModel.cpp
1817
src/Model/UnitConverter.cpp

include/ifcpp/Geometry/CurveConverter.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,18 @@ class CurveConverter {
7777
TCurve ConvertCurve( const std::shared_ptr<IfcCurve>& curve ) {
7878
// ENTITY IfcCurve ABSTRACT SUPERTYPE OF (ONEOF(IfcBoundedCurve, IfcConic, IfcLine, IfcOffsetCurve2D, IfcOffsetCurve3D, IfcPCurve))
7979

80+
TCurve* cached = nullptr;
8081
{
8182
#ifdef ENABLE_OPENMP
8283
ScopedLock lock( this->m_curveToPointsMapMutex );
8384
#endif
8485
if( this->m_curveToPointsMap.contains( curve ) ) {
85-
return this->m_curveToPointsMap[ curve ];
86+
cached = &this->m_curveToPointsMap[ curve ];
8687
}
8788
}
89+
if( cached ) {
90+
return *cached;
91+
}
8892

8993
TCurve result;
9094

@@ -264,7 +268,9 @@ class CurveConverter {
264268
#ifdef ENABLE_OPENMP
265269
ScopedLock lock( this->m_curveToPointsMapMutex );
266270
#endif
267-
this->m_curveToPointsMap[ curve ] = std::move( resultCopy );
271+
if( !this->m_curveToPointsMap.contains( curve ) ) {
272+
this->m_curveToPointsMap[ curve ] = std::move( resultCopy );
273+
}
268274
}
269275
return result;
270276
}

include/ifcpp/Geometry/GeometryGenerator.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class GeometryGenerator {
153153
{
154154
ScopedLock lock( entitiesPtrMutex );
155155
Helpers::AppendTo( entitiesPtr, entitiesPerThread );
156-
};
156+
}
157157
}
158158
#endif
159159
return entities;
@@ -246,7 +246,9 @@ class GeometryGenerator {
246246
#ifdef ENABLE_OPENMP
247247
ScopedLock lock( this->m_representationToVisualObjectMapMutex );
248248
#endif
249-
this->m_representationToVisualObjectMap[ representation ] = std::move( resultCopy );
249+
if( !this->m_representationToVisualObjectMap.contains( representation ) ) {
250+
this->m_representationToVisualObjectMap[ representation ] = std::move( resultCopy );
251+
}
250252
}
251253
return visualObjects;
252254
}
@@ -294,7 +296,9 @@ class GeometryGenerator {
294296
#ifdef ENABLE_OPENMP
295297
ScopedLock lock( this->m_representationItemToVisualObjectMapMutex );
296298
#endif
297-
this->m_representationItemToVisualObjectMap[ item ] = std::move( resultCopy );
299+
if( !this->m_representationItemToVisualObjectMap.contains( item ) ) {
300+
this->m_representationItemToVisualObjectMap[ item ] = std::move( resultCopy );
301+
}
298302
}
299303
return visualObjects;
300304
}

include/ifcpp/Geometry/Helpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Helpers {
2424
}
2525

2626
template<CAdapter TAdapter>
27-
static std::vector<typename TAdapter::TTriangle> CreateTriangles( const std::shared_ptr<TAdapter> adapter,
27+
static std::vector<typename TAdapter::TTriangle> CreateTriangles( const std::shared_ptr<TAdapter>& adapter,
2828
const std::vector<std::vector<typename TAdapter::TVector>>& loops ) {
2929
std::vector<typename TAdapter::TTriangle> result;
3030
for( const auto& l: loops ) {
@@ -44,7 +44,7 @@ class Helpers {
4444
}
4545

4646
template<CAdapter TAdapter>
47-
static typename TAdapter::TMesh CreateMesh( const std::shared_ptr<TAdapter> adapter, const std::vector<std::vector<typename TAdapter::TVector>>& loops ) {
47+
static typename TAdapter::TMesh CreateMesh( const std::shared_ptr<TAdapter>& adapter, const std::vector<std::vector<typename TAdapter::TVector>>& loops ) {
4848
return adapter->CreateMesh( Helpers::CreateTriangles( adapter, loops ) );
4949
}
5050
};

include/ifcpp/Geometry/ProfileConverter.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,18 @@ class ProfileConverter {
7777
// ENTITY IfcProfileDef SUPERTYPE OF(ONEOF(IfcArbitraryClosedProfileDef, IfcArbitraryOpenProfileDef, IfcCompositeProfileDef, IfcDerivedProfileDef,
7878
// IfcParameterizedProfileDef));
7979

80+
std::vector<TVector>* cached = nullptr;
8081
{
8182
#ifdef ENABLE_OPENMP
8283
ScopedLock lock( this->m_profileToPointsMapMutex );
8384
#endif
8485
if( this->m_profileToPointsMap.contains( profile ) ) {
85-
return this->m_profileToPointsMap[ profile ];
86+
cached = &this->m_profileToPointsMap[ profile ];
8687
}
8788
}
89+
if( cached ) {
90+
return *cached;
91+
}
8892

8993
std::vector<TVector> result;
9094

@@ -119,7 +123,9 @@ class ProfileConverter {
119123
#ifdef ENABLE_OPENMP
120124
ScopedLock lock( this->m_profileToPointsMapMutex );
121125
#endif
122-
this->m_profileToPointsMap[ profile ] = std::move( resultCopy );
126+
if( !this->m_profileToPointsMap.contains( profile ) ) {
127+
this->m_profileToPointsMap[ profile ] = std::move( resultCopy );
128+
}
123129
}
124130

125131
return result;

include/ifcpp/Geometry/SolidConverter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ class SolidConverter {
207207
#ifdef ENABLE_OPENMP
208208
ScopedLock lock( this->m_booleanResultToVisualObjectMapMutex );
209209
#endif
210-
this->m_booleanResultToVisualObjectMap[ booleanResult ] = std::move( resultCopy );
210+
if( !this->m_booleanResultToVisualObjectMap.contains( booleanResult ) ) {
211+
this->m_booleanResultToVisualObjectMap[ booleanResult ] = std::move( resultCopy );
212+
}
211213
}
212214
return operand1;
213215
}

include/ifcpp/Geometry/StyleConverter.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,18 @@ class StyleConverter {
112112
std::vector<std::shared_ptr<Style>> ConvertPresentationStyle( const shared_ptr<IfcPresentationStyle>& presentationStyle ) {
113113
// ENTITY IfcPresentationStyle ABSTRACT SUPERTYPE OF(ONEOF(IfcCurveStyle, IfcFillAreaStyle, IfcSurfaceStyle, IfcSymbolStyle, IfcTextStyle));
114114

115+
std::vector<std::shared_ptr<Style>>* cached = nullptr;
115116
{
116117
#ifdef ENABLE_OPENMP
117118
ScopedLock lock( this->m_presentationStyleToStylesMapMutex );
118119
#endif
119120
if( this->m_presentationStyleToStylesMap.contains( presentationStyle ) ) {
120-
return this->m_presentationStyleToStylesMap[ presentationStyle ];
121+
cached = &this->m_presentationStyleToStylesMap[ presentationStyle ];
121122
}
122123
}
124+
if( cached ) {
125+
return *cached;
126+
}
123127

124128
std::vector<std::shared_ptr<Style>> result;
125129

@@ -145,11 +149,14 @@ class StyleConverter {
145149
result = {};
146150
}
147151

152+
auto resultCopy = result;
148153
{
149154
#ifdef ENABLE_OPENMP
150155
ScopedLock lock( this->m_presentationStyleToStylesMapMutex );
151156
#endif
152-
this->m_presentationStyleToStylesMap[ presentationStyle ] = result;
157+
if( !this->m_presentationStyleToStylesMap.contains( presentationStyle ) ) {
158+
this->m_presentationStyleToStylesMap[ presentationStyle ] = std::move( resultCopy );
159+
}
153160
}
154161

155162

src/Model/AttributeObject.cpp

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)