Skip to content

Conversation

@SyMind
Copy link
Collaborator

@SyMind SyMind commented Nov 6, 2025

This PR fixes UTF-16 encoding issues in source map generation by correctly handling multi-byte Unicode characters. The changes ensure that column positions in source maps are calculated using UTF-16 code units instead of UTF-8 bytes, which is required for proper JavaScript source map compatibility.

  • Replaces all uses of Cow<'a, str> with &'a str in chunk processing to simplify the API
  • Updates column offset calculations to use UTF-16 code unit counts instead of byte offsets
  • Refactors remaining replacement handling to process replacements individually instead of concatenating them

Copilot AI review requested due to automatic review settings November 6, 2025 12:33
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 6, 2025

CodSpeed Performance Report

Merging #202 will not alter performance

Comparing perf-on-chunk-to-str (5dded2e) with main (446ceaf)

Summary

✅ 11 untouched
⏩ 6 skipped1

Footnotes

  1. 6 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes UTF-16 encoding issues in source map generation by correctly handling multi-byte Unicode characters. The changes ensure that column positions in source maps are calculated using UTF-16 code units instead of UTF-8 bytes, which is required for proper JavaScript source map compatibility.

  • Replaces all uses of Cow<'a, str> with &'a str in chunk processing to simplify the API
  • Updates column offset calculations to use UTF-16 code unit counts instead of byte offsets
  • Refactors remaining replacement handling to process replacements individually instead of concatenating them

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/replace_source.rs Core fix for UTF-16 column calculations; refactored replacement handling logic; added comprehensive test coverage for multi-byte Unicode
src/original_source.rs Updated column calculations to use UTF-16 encoding; added test for multi-unit UTF-16 characters
src/helpers.rs Changed OnChunk type signature from Cow<'b, str> to &'b str; updated all call sites
src/cached_source.rs Minor reordering of struct fields

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SyMind SyMind force-pushed the perf-on-chunk-to-str branch 8 times, most recently from 3a7b5de to 5b28db1 Compare November 6, 2025 16:06
@SyMind SyMind force-pushed the perf-on-chunk-to-str branch 5 times, most recently from 4792cee to 702d86b Compare November 7, 2025 02:34
@SyMind SyMind force-pushed the perf-on-chunk-to-str branch from cfa2c78 to 3f7670a Compare November 7, 2025 03:10
@SyMind SyMind changed the title perf: on chunk pass &str fix: fixes UTF-16 encoding issues Nov 7, 2025
@SyMind SyMind merged commit ee72991 into main Nov 7, 2025
10 checks passed
@SyMind SyMind deleted the perf-on-chunk-to-str branch November 7, 2025 05:44
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