Skip to content

[binary-reader] Templatize LEB reading functions. NFC - #2771

Merged
sbc100 merged 1 commit into
mainfrom
ReadLeb
Jun 23, 2026
Merged

sbc100 merged 1 commit into
mainfrom
ReadLeb

Conversation

@sbc100

@sbc100 sbc100 commented Jun 23, 2026

Copy link
Copy Markdown
Member

No description provided.

@sbc100 sbc100 changed the title [binary-reader] Templatize LEB reading functions. [binary-reader] Templatize LEB reading functions. NFC Jun 23, 2026
@sbc100
sbc100 requested a review from zherczeg June 23, 2026 05:41
Comment thread src/binary-reader.cc
template <typename T, size_t (*ReadFn)(const uint8_t*, const uint8_t*, T*)>
Result BinaryReader::ReadLeb128(T* out_value,
const char* desc,
const char* type_name) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we encode this as template arg?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would mean defining separate static consts like:

    constexpr char kU32Name[] = "u32";
    constexpr char kU64Name[] = "u64";
    constexpr char kI32Name[] = "i32";
    constexpr char kI64Name[] = "i64";

Which I think makes the code a little less readable. Is there some big advantage to doing that?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about two args: bool signed (or char signed) and int bits?
The advantage of templates is pre-computing consts.
If you prefer we can leave the code this way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we land this change and you can propose a following you like?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@zherczeg

Copy link
Copy Markdown
Collaborator

I like this idea!

@zherczeg zherczeg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sbc100
sbc100 enabled auto-merge (squash) June 23, 2026 16:55
@sbc100
sbc100 disabled auto-merge June 23, 2026 16:55
@sbc100
sbc100 merged commit 1bccd72 into main Jun 23, 2026
33 checks passed
@sbc100
sbc100 deleted the ReadLeb branch June 23, 2026 16:55
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.

2 participants