Skip to content

PDF: const-qualify scalar by-value constructor params#576

Merged
andiwand merged 3 commits into
mainfrom
pdf-const-consistency
Jun 28, 2026
Merged

PDF: const-qualify scalar by-value constructor params#576
andiwand merged 3 commits into
mainfrom
pdf-const-consistency

Conversation

@andiwand

@andiwand andiwand commented Jun 28, 2026

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

Summary

Follow-up const-consistency sweep across the pdf module. The codebase
convention is to const-qualify cheap scalar by-value parameters in
definitions; this adds the two stragglers that were missing it:

  • ExponentialFunction(..., const double n)
  • SampledFunction(..., const std::int32_t bits_per_sample, ...)

Why the diff is small

Guiding rule: what can be const without hurting performance (move) should
be const
. A full scan of the module found that nearly every object/vector
by-value parameter is std::move'd into a member (or otherwise mutated), so
const-qualifying them would defeat the move — those correctly stay non-const.
The genuinely missing cases were just these two scalar constructor params.
One other candidate (uint_to_code's value) is shifted in-place, so it
also correctly remains non-const.

Testing

cmake --build cmake-build-relwithdebinfo --target odr — builds clean.

andiwand and others added 3 commits June 28, 2026 20:30
Add top-level const to the cheap scalar by-value parameters `n`
(ExponentialFunction) and `bits_per_sample` (SampledFunction), matching
the codebase convention of const-qualifying scalar params in definitions.
Object/vector params stay non-const because they are std::move'd into
members, so adding const would defeat the move.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uqx1dUpDUykRxui8FYwxvM
Extend #576's convention to the two constructors defined inline in
pdf_document_element.hpp: add top-level const to the cheap copied-not-
moved by-value params `width` (Iterator, CodeRange) and `codes`
(CodeRange), mirroring the existing BitReader(const std::string_view
data, const std::size_t byte_offset) in pdf_image.cpp. Top-level const
on a value param does not change the function type, so callers and ABI
are unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uqx1dUpDUykRxui8FYwxvM
@andiwand andiwand enabled auto-merge (squash) June 28, 2026 19:05
@andiwand andiwand merged commit 7550a00 into main Jun 28, 2026
11 checks passed
@andiwand andiwand deleted the pdf-const-consistency branch June 28, 2026 19:35
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