Repository navigation
Use constant metadata tables and per-model string pools - #265
Merged
danoli3 merged 3 commits intoNov 9, 2026
Merged
Conversation
Store metadata descriptors in sorted constant arrays instead of constructing per-model maps at initialization. Binary search handles tag IDs; reverse name lookup preserves the existing lowest-ID result for duplicate names. Descriptors and their strings keep static storage duration. Keep every current upstream table, including the empty Apple iOS model, and preserve tag IDs, strings, public model mappings, and unknown-tag fallbacks. Metadata initialization now performs zero allocations. In a native x86-64 measurement, the current tables previously retained 64,752 requested bytes in 1,349 allocations per initialized library instance. Add a standalone metadata regression test covering all 16-bit tag IDs for every registered model, sorted table invariants, reverse names, stable pointers, unknown models, and fallback strings.
Replace metadata string pointers with compiler-computed 16-bit offsets. Keep each model in its own constant pool so unused models can be discarded. A compile-time bound prevents offset overflow; no generator, heap allocation or runtime initialization is needed. Preserve the existing getters. Move the table rows and their original attribution to TagLibData.h. Update header dependencies and add exhaustive string, offset and lookup coverage.
Add an internal getTagFields method and use it at the ten callers that request both strings. This avoids repeating model dispatch and binary search. Keep the original three-argument getTagFieldName symbol as a wrapper, and leave getTagDescription available. Check both outputs for every model and 16-bit tag ID, including missing descriptions, unknown tags and fallback buffers. Verify that the original member-function signature and returned names are preserved.
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.
TagLib currently builds heap-allocated maps for fixed metadata tables. This series makes those tables constant, replaces string pointers with 16-bit pool offsets, and shares the lookup when a caller needs both a tag name and description.
The three commits are separated for review:
sizeof/offsetofcompute the layout in C++98; a compile-time bound checks each pool. Rows remain editable inTagLibData.h, with no generator, runtime initialization, heap allocation, or mutable cache. Preserve the existing table attribution and this fork's copyright notice.getTagFieldsfor the ten callers requesting both strings. Keep the original three-argumentgetTagFieldNamesymbol andgetTagDescription. The public FreeImage C API is unchanged. Sharing the search reduces duplicate work; the pool representation still adds offset decoding, so this is not a claim that every individual lookup gets faster.This is a port of SourceForge patch #199 and its two follow-ups. This fork's newer parser fixes and existing line endings are preserved. The standalone metadata regression is registered with CTest when
BUILD_TESTS=ON, with assertions enabled in Release builds; legacy Makefile dependencies include the new header as well.Validation on Linux:
Build and test commands:
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON -DFREEIMAGE_STATIC=ON cmake --build build --parallel 8 ctest --test-dir build --output-on-failure make -C TestAPI/Metadata check