Skip to content

Commit

Permalink
perf: optimize feature cache to RAM layer handling
Browse files Browse the repository at this point in the history
  • Loading branch information
LandscapeLab Office committed Feb 20, 2024
1 parent 2ce2ba8 commit b90103e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/vector-extractor/NativeLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ NativeLayer::NativeLayer(OGRLayer *layer) : layer(layer) {
}

void NativeLayer::write_feature_cache_to_ram_layer() {
for (auto feature_list : feature_cache) {
auto feature = feature_list.second.front();
ram_layer->ResetReading();

// Iterate over RAM layer, update with cached features
// Not the other way around because we'll usually have far more cached features than total features in the RAM layer
OGRFeature *feature = ram_layer->GetNextFeature();

if (!feature->is_deleted) {
if (ram_layer->GetFeature(feature->feature->GetFID())) {
OGRErr error = ram_layer->SetFeature(feature->feature);
}
while (feature != nullptr) {
if (feature_cache.find(feature->GetFID()) != feature_cache.end()) {
OGRErr error = ram_layer->SetFeature(feature_cache[feature->GetFID()].front()->feature);
}

auto feature = ram_layer->GetNextFeature();
}
}

Expand Down Expand Up @@ -263,6 +267,7 @@ std::list<std::shared_ptr<Feature> > NativeLayer::get_features_inside_geometry(O
// unless they're more
// than the given max_amount.
int num_features = layer->GetFeatureCount();

int iterations = std::min(num_features, max_amount);

for (int i = 0; i < iterations; i++) {
Expand Down

0 comments on commit b90103e

Please sign in to comment.