Skip to content

Keep each TIFF directory entry and its value in their own heap blocks, as C++ does - #40

Open
kunpai wants to merge 1 commit into
google:masterfrom
kunpai:tiff-entries-on-heap
Open

kunpai wants to merge 1 commit into
google:masterfrom
kunpai:tiff-entries-on-heap

Conversation

@kunpai

@kunpai kunpai commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Keep each TIFF directory entry and its value in their own heap blocks, as C++ does

Problem

TiffDirectory (C++, Rust) holds the entries the TIFF parser reads. C++ keeps them in a std::map, so each entry is its own heap node, and each value is a std::vector with its own heap buffer, even when it is 1 byte. The port keeps the entries in one Vec and stores a value of 8 bytes or less inside the entry, so only a longer value gets a heap buffer.

For example, heap blocks for the entries and their values in GetPreviewImageData, GetDngInformation and GetOrientation:

C++ Rust
DNG, 43 entries 86 3
NEF, 21 entries 42 3
CR3, 15 entries 30 3

What each call returns is the same on both sides.

Question

Which behaviour do we want: C++'s or the Rust port's? Specifically, should each directory entry be its own heap block, with its value in its own heap buffer (like the C++ library), or a slot in one Vec with a value of 8 bytes or less stored inside it (like the Rust port)?

This PR implements C++'s behaviour.

Fix

The examples above then match C++ (C++ in blue, the port in red, this PR in green):

P18-heap-blocks

What each call returns does not change, on these files and on a file of each other format piex reads, and the port's tests pass (44 + 174).

A note for review:

  • Peak and stack: on these files the peak heap is set by other buffers, so it stays within 50 bytes of what it is today, and this PR adds no stack buffers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant