Skip to content

src: use constexpr table for GetOctalCode#64471

Open
ansh1406 wants to merge 1 commit into
nodejs:mainfrom
ansh1406:src-constexpr-octal-table
Open

src: use constexpr table for GetOctalCode#64471
ansh1406 wants to merge 1 commit into
nodejs:mainfrom
ansh1406:src-constexpr-octal-table

Conversation

@ansh1406

Copy link
Copy Markdown

Replaced the runtime std::vector<std::string> cache used by GetOctalCode() with a compile-time constexpr lookup table of std::string_view.

Changes

  1. GetOctalCode() now returns std::string_view instead of const std::string&.

  2. There are two call sites that use GetOctalCode():

    • src/node_snapshotable.cc: The returned value is streamed directly to an std::ostream, so no changes were required.
    • tools/js2c.cc: Updated the implementation to use std::string_view::data() instead of std::string::c_str().

Verification

  • Verified that the generated output is identical for all 256 byte values.
  • Full build completed successfully on Debian 13.4 (x86_64, GCC, make).

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. tools Issues and PRs related to the tools directory. labels Jul 13, 2026
Replace the runtime std::vector<std::string> cache in
GetOctalCode() with a compile-time constexpr lookup table of
std::string_view

Signed-off-by: Ansh Swaroop <anshswaroop14@gmail.com>
@ansh1406 ansh1406 force-pushed the src-constexpr-octal-table branch from eb5cd72 to 9e25225 Compare July 13, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. tools Issues and PRs related to the tools directory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants