Skip to content

refactor: simplify SourceMapBuilder string storage#361

Merged
Boshen merged 1 commit into
mainfrom
codex/simplify-sourcemap-builder-borrows
Jun 15, 2026
Merged

refactor: simplify SourceMapBuilder string storage#361
Boshen merged 1 commit into
mainfrom
codex/simplify-sourcemap-builder-borrows

Conversation

@Boshen

@Boshen Boshen commented Jun 15, 2026

Copy link
Copy Markdown
Member

Refactor SourceMapBuilder to store borrowed strings directly and allocate owned strings only in into_owned_sourcemap.

Checks:

  • cargo test
  • cargo clippy --all-targets --all-features
  • typos

@codspeed-hq

codspeed-hq Bot commented Jun 15, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 4.52%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
✅ 14 untouched benchmarks
⏩ 5 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
build_single 6.2 µs 5.8 µs +6.75%
serialize[real_medium] 5.1 µs 5 µs +2.33%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing codex/simplify-sourcemap-builder-borrows (7805d07) with main (26834e5)

Open in CodSpeed

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Boshen
Boshen marked this pull request as ready for review June 15, 2026 05:31
@Boshen
Boshen merged commit c1b338e into main Jun 15, 2026
8 checks passed
@Boshen
Boshen deleted the codex/simplify-sourcemap-builder-borrows branch June 15, 2026 05:31
@oxc-guard oxc-guard Bot mentioned this pull request Jun 15, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7805d07c0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sourcemap_builder.rs
/// `source_content` is borrowed for `'a` — the content is never copied.
pub fn set_source_and_content(&mut self, source: Cow<'a, str>, source_content: &'a str) -> u32 {
/// The source name and source content are borrowed for `'a` — neither is copied.
pub fn set_source_and_content(&mut self, source: &'a str, source_content: &'a str) -> u32 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restore owned source-name support

When callers build source names from Path::to_string_lossy() or a formatted String inside a loop and then call into_owned_sourcemap, the previous Cow<'a, str> parameter let the builder take ownership of those transient source names. Requiring &'a str now forces downstream code to keep every generated String alive until the builder is consumed, and existing Cow call sites no longer compile, so this is a public API and usability regression for generated/non-UTF8 paths while building owned sourcemaps.

Useful? React with 👍 / 👎.

Boshen added a commit that referenced this pull request Jun 19, 2026
Mirror the `SourceMapBuilder` change in #361: store `&'a str` internally
instead of `Cow<'a, str>` and defer the borrow-vs-own decision to the
terminal methods. Adds `into_owned_sourcemap` alongside `into_sourcemap`
to match the `SourceMapBuilder` surface.

The public API is backward compatible (fields are `pub(crate)`, existing
method signatures are unchanged).
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