Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Unified Diff: runtime/vm/object.cc

Issue 2400523003: Fix bad canonicalization for strings whose utf32->utf16 conversion is lossy. (Closed)
Patch Set: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/object_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index c0024b9cea9b6304a2a260873056371036236046..efa41b723b7f6737a137b8a417bc987f18df6d7c 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -20097,19 +20097,21 @@ bool String::Equals(const uint16_t* utf16_array, intptr_t len) const {
bool String::Equals(const int32_t* utf32_array, intptr_t len) const {
- CodePointIterator it(*this);
- intptr_t i = 0;
- bool has_more = it.Next();
- while (has_more && (i < len)) {
- if ((it.Current() != static_cast<int32_t>(utf32_array[i]))) {
- return false;
+ if (len < 0) return false;
+ intptr_t j = 0;
+ for (intptr_t i = 0; i < len; ++i) {
+ if (Utf::IsSupplementary(utf32_array[i])) {
+ uint16_t encoded[2];
+ Utf16::Encode(utf32_array[i], &encoded[0]);
+ if (j + 1 >= Length()) return false;
+ if (CharAt(j++) != encoded[0]) return false;
+ if (CharAt(j++) != encoded[1]) return false;
+ } else {
+ if (j >= Length()) return false;
+ if (CharAt(j++) != utf32_array[i]) return false;
}
- // Advance both streams forward.
- ++i;
- has_more = it.Next();
}
- // Strings are only true iff we reached the end in both streams.
- return (i == len) && !has_more;
+ return j == Length();
}
« no previous file with comments | « no previous file | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698