fix: track source pointers in layer/state duplication#381
Merged
spe-ciellt merged 1 commit intogerbv:developfrom Mar 14, 2026
Merged
Conversation
The layer/state duplication logic compared currentNet->layer against lastLayer, but lastLayer is a *duplicated* pointer that will never equal a source pointer. This caused every net to create a redundant duplicate layer and state, wasting O(n) memory. Track source pointers (srcLayer, srcState) separately and compare against those to correctly detect when consecutive nets share the same layer or state, avoiding unnecessary duplication. Extracted from gerbv#163.
This was referenced Mar 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a comparison bug in
gerbv_image_copy_all_nets()that caused O(n) redundant layer and state allocations during image merging/export.The existing code compared
currentNet->layer != lastLayer, butlastLayerpointed to a duplicated struct — it could never equal a source pointer. Every net therefore created a new duplicate layer and state, even when consecutive nets shared the same source layer/state.srcLayer,srcState) separately from duplicated pointersgerbv_image_duplicate_layer()/gerbv_image_duplicate_state()callsThis complements PR #379 (which added
->next = NULLinitialization to the duplicate functions to prevent use-after-free on export).Attribution
Extracted from #163 (@meantaipan).
Test plan
cmake --preset linux-gnu-gcc && cmake --build build— clean buildctest -C Debug— 94/105 pass (11 pre-existing mismatches, unchanged from develop)