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

Unified Diff: runtime/vm/object.cc

Issue 11418095: Use the code point iterator in equality comparisons to C strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | no next file » | 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 cb15a98b12cae59a0536892b14372ca4be284815..cf65b01cc5bceea73b1ab0c3245a9536e12685fa 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -10035,26 +10035,26 @@ bool String::Equals(const Instance& other) const {
}
-bool String::Equals(const char* utf8_array) const {
- ASSERT(utf8_array != NULL);
- intptr_t len = strlen(utf8_array);
- for (intptr_t i = 0; i < this->Length(); ++i) {
- if (*utf8_array == '\0') {
+bool String::Equals(const char* str) const {
siva 2012/11/20 19:47:32 yes cstr would be a better name. Also please chang
cshapiro 2012/11/20 23:41:12 Done. All of the C-strings in the dart VM are ass
+ ASSERT(str != NULL);
+ CodePointIterator it(*this);
+ intptr_t len = strlen(str);
+ while (it.Next()) {
+ if (*str == '\0') {
// Lengths don't match.
return false;
}
int32_t ch;
- intptr_t consumed = Utf8::Decode(
- reinterpret_cast<const uint8_t*>(utf8_array),
- len,
- &ch);
- if (consumed == 0 || this->CharAt(i) != ch) {
+ intptr_t consumed = Utf8::Decode(reinterpret_cast<const uint8_t*>(str),
+ len,
+ &ch);
+ if (consumed == 0 || it.Current() != ch) {
return false;
}
- utf8_array += consumed;
+ str += consumed;
len -= consumed;
}
- return *utf8_array == '\0';
+ return *str == '\0';
}
siva 2012/11/20 19:47:32 We should add a test case for this in order to ens
cshapiro 2012/11/20 23:41:12 Done.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698