Skip to content

Use byte indices instead of char indices for text runs - #10895

Merged
bors-servo merged 4 commits into
servo:masterfrom
mbrubeck:byteindex
Apr 29, 2016
Merged

bors-servo merged 4 commits into
servo:masterfrom
mbrubeck:byteindex

Conversation

@mbrubeck

@mbrubeck mbrubeck commented Apr 28, 2016 •

Copy link
Copy Markdown
Contributor

Replace character indices with UTF-8 byte offsets throughout all code dealing with text runs. This eliminates a lot of complexity when converting from one to the other, and interoperates better with the rest of the Rust ecosystem.

For most code this is just a simple replacement of char indices with byte indices. In a few places like glyph storage and text fragment scanning, it also lets us get rid of code that existed only to map between bytes and chars.

Also includes some related fixes to text shaping, discovered while working on this conversion. See the commit messages for details.

r? @pcwalton


This change is Reviewable

Shaper::save_glyph_results incorrectly starts its loop by setting glyph_span
to a length of 1.  This means that the `if glyph_span.len() == 0` test in the
inner loop will never succeed.

Instead the glyph span should start out empty, and a glyph should be added only
as the corresponding char is found.  For comparison, see the Gecko code this
was ported from:

https://hg.mozilla.org/mozilla-central/file/ab0044bf/gfx/thebes/gfxHarfBuzzShaper.cpp#l1682
This is a no-op, since a "non-glyph" is simply `GlyphEntry(0)`. This is the
same as `GlyphEntry::initial()`, which all the entries are already initialized
to.
@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/htmltextareaelement.rs, components/script/dom/htmlinputelement.rs

@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Apr 28, 2016
@mbrubeck

Copy link
Copy Markdown
Contributor Author

@bors-servo try

bors-servo pushed a commit that referenced this pull request Apr 28, 2016
Use byte indices instead of char indices for text runs

Replace character indices with UTF-8 byte offsets throughout all code dealing with text runs.  This eliminates a lot of complexity when converting from one to the other, and interoperates better with the rest of the Rust ecosystem.

For most code this is just a simple replacement of char indices with byte indices.  In a few places like glyph storage and text fragment scanning, it also lets us get rid of code that existed only to map between bytes and chars.

Also includes some related fixes to text shaping, discovered while working on this conversion.  See the commit messages for details.

r? @pcwalton

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10895)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 5e49a92 with merge 58e7865...

@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Apr 28, 2016
@highfive

Copy link
Copy Markdown
  ▶ FAIL [expected PASS] /_mozilla/css/submit_focus_a.html
  └   → /_mozilla/css/submit_focus_a.html 3d3190e5b4a800f4418abbb2c0f9a440b124a4bc
/_mozilla/css/submit_focus_b.html 69459c6973cf8bf615a79d90b7e480d60981b795
Testing 3d3190e5b4a800f4418abbb2c0f9a440b124a4bc == 69459c6973cf8bf615a79d90b7e480d60981b795

@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Apr 28, 2016
@mbrubeck

mbrubeck commented Apr 28, 2016 •

Copy link
Copy Markdown
Contributor Author

▶ FAIL [expected PASS] /_mozilla/css/submit_focus_a.html

Fixed. (I accidentally removed an input_type check in HtmlInputElement::selection_for_layout.)

Replace character indices with UTF-8 byte offsets throughout the code dealing
with text shaping and breaking.  This eliminates a lot of complexity when
converting from one to the other, and interoperates better with the rest of
the Rust ecosystem.
@pcwalton

pcwalton commented Apr 28, 2016 •

Copy link
Copy Markdown
Contributor

@bors-servo: r+

This is awesome!

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit c4872d9 has been approved by pcwalton

1 similar comment
@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit c4872d9 has been approved by pcwalton

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Apr 28, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit c4872d9 with merge 4e15586...

bors-servo pushed a commit that referenced this pull request Apr 29, 2016
Use byte indices instead of char indices for text runs

Replace character indices with UTF-8 byte offsets throughout all code dealing with text runs.  This eliminates a lot of complexity when converting from one to the other, and interoperates better with the rest of the Rust ecosystem.

For most code this is just a simple replacement of char indices with byte indices.  In a few places like glyph storage and text fragment scanning, it also lets us get rid of code that existed only to map between bytes and chars.

Also includes some related fixes to text shaping, discovered while working on this conversion.  See the commit messages for details.

r? @pcwalton

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10895)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - windows

@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Apr 29, 2016
@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Apr 29, 2016
@mbrubeck

mbrubeck commented Apr 29, 2016 •

Copy link
Copy Markdown
Contributor Author

@bors-servo retry

Infrastructure

@bors-servo

Copy link
Copy Markdown
Contributor

⚡ Previous build results for android, arm32, arm64, linux-dev, mac-dev-unit, mac-rel-css, mac-rel-wpt are reusable. Rebuilding only linux-rel, windows...

@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - windows

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Apr 29, 2016
@mbrubeck

Copy link
Copy Markdown
Contributor Author

@bors-servo retry

@larsbergstrom

Copy link
Copy Markdown
Contributor

cc me

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit c4872d9 with merge cf121ad...

bors-servo pushed a commit that referenced this pull request Apr 29, 2016
Use byte indices instead of char indices for text runs

Replace character indices with UTF-8 byte offsets throughout all code dealing with text runs.  This eliminates a lot of complexity when converting from one to the other, and interoperates better with the rest of the Rust ecosystem.

For most code this is just a simple replacement of char indices with byte indices.  In a few places like glyph storage and text fragment scanning, it also lets us get rid of code that existed only to map between bytes and chars.

Also includes some related fixes to text shaping, discovered while working on this conversion.  See the commit messages for details.

r? @pcwalton

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10895)
<!-- Reviewable:end -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Apr 29, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows

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.

5 participants