Skip to content

perf(string): consolidate basic_string::write overloads (refs #3122 B5 / #2886 Stage 5) - #3152

Merged
zackees merged 1 commit into
masterfrom
feat/3122-b5-basic-string-write
Jun 16, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/3122-b5-basic-string-write

Conversation

@zackees

@zackees zackees commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

B5 of meta #3122, Stage 5 of #2886.

Three trivial delegates that previously each rebuilt a const char* pointer via an unnecessary static_cast<const void*> → bit_cast_ptr chain (write(u8*)) or took the address of a single byte then bit_cast'd it (write(u8)) are now simple one-line tail-calls:

// Before:
fl::size basic_string::write(const fl::u8* data, fl::size n) {
    const char* str = fl::bit_cast_ptr<const char>(static_cast<const void*>(data));
    return write(str, n);
}
fl::size basic_string::write(fl::u8 c) {
    const char* str = fl::bit_cast_ptr<const char>(static_cast<const void*>(&c));
    return write(str, 1);
}

// After:
fl::size basic_string::write(const fl::u8* data, fl::size n) {
    return write(fl::bit_cast_ptr<const char>(data), n);
}
fl::size basic_string::write(fl::u8 c) {
    return write(static_cast<char>(c));
}

Net per-call-site savings: a few bytes — the order of magnitude the meta projected for Stage 5 (~0.5-1 KB across all call sites).

Validation

  • bash test fl_stl_string --cpp — passes.
  • bash lint --cpp — clean.

Initial reinterpret_cast attempt was rejected by the project's ReinterpretCastChecker; bit_cast_ptr is the project-preferred form for this kind of pointer-type conversion.

Refs #3122 B5, #2886 Stage 5.

Summary by CodeRabbit

  • Refactor
    • Simplified internal string write method implementations by removing unnecessary casting indirection and improving code clarity through enhanced comments.

…5 / #2886 Stage 5)

Three trivial delegates that previously each rebuilt a const char*
pointer via an unnecessary static_cast<const void*> → bit_cast_ptr
chain (write(u8*)) or address-of a single byte then bit_cast that
(write(u8)) are now simple one-line tail-calls:

  write(const fl::u8* data, fl::size n)
      Drops the static_cast<const void*> intermediate; bit_cast_ptr
      handles the u8*→char* conversion directly.
  write(fl::u8 c)
      Delegates to write(char) via static_cast<char> instead of
      taking the address of c and pushing it through the void*+
      bit_cast pipeline.
  write(char c)
      Unchanged.

Net effect on each call site is a few bytes — exactly the order of
magnitude the meta projected for Stage 5 (~0.5-1 KB).

Validated by:
- bash test fl_stl_string --cpp — passes (no behavioral change; both
  fl::u8 and char are the same physical byte, and bit_cast_ptr emits
  the same pointer that the prior bit_cast did).
- bash lint --cpp — clean (initial reinterpret_cast attempt rejected
  by the project's ReinterpretCastChecker; bit_cast_ptr is the
  project-preferred form for this kind of pointer-type conversion).

Refs #3122 B5, #2886 Stage 5.
@coderabbitai

coderabbitai Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 76968cdd-3261-4183-819f-879d462c7dd7

📥 Commits

Reviewing files that changed from the base of the PR and between 18ad097 and a6a644d.

📒 Files selected for processing (1)
  • src/fl/stl/basic_string.cpp.hpp

📝 Walkthrough

Walkthrough

Two basic_string write overloads for fl::u8 are simplified: write(const fl::u8*, fl::size) now uses fl::bit_cast_ptr<const char> directly on the pointer, and write(fl::u8) casts the byte to char and calls write(char), removing previous intermediate cast indirections. Explanatory comments were added.

basic_string u8 write() simplification

Layer / File(s) Summary
Simplify write(u8*, size) and write(u8) overloads
src/fl/stl/basic_string.cpp.hpp
write(const fl::u8*, fl::size) delegates via fl::bit_cast_ptr<const char> directly; write(fl::u8) casts to char and forwards to write(char), replacing the prior bit-cast-address approach. Comments describe both simplifications.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A byte walks in, no detours to take,
bit_cast_ptr does the cast with no mistake.
The old void* path? Gone with a hop,
A char is a char — no reason to stop!
🐇 Simpler roads lead to cleaner burrows.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/3122-b5-basic-string-write

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees
zackees merged commit aa163d9 into master Jun 16, 2026
9 of 10 checks passed
@zackees
zackees deleted the feat/3122-b5-basic-string-write branch June 16, 2026 03:40
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 16, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant