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

Unified Diff: runtime/lib/string.cc

Issue 560113002: Narrow String::CharAt from int32_t to uint16_t. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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/dart_api_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string.cc
diff --git a/runtime/lib/string.cc b/runtime/lib/string.cc
index 2573b9ae0042e494926498af1793436151534223..bb147a1a7e85db3f9f55a6a43742200253966c47 100644
--- a/runtime/lib/string.cc
+++ b/runtime/lib/string.cc
@@ -218,7 +218,7 @@ DEFINE_NATIVE_ENTRY(String_getLength, 1) {
}
-static int32_t StringValueAt(const String& str, const Integer& index) {
+static uint16_t StringValueAt(const String& str, const Integer& index) {
if (index.IsSmi()) {
const intptr_t index_value = Smi::Cast(index).Value();
if ((0 <= index_value) && (index_value < str.Length())) {
@@ -235,20 +235,17 @@ static int32_t StringValueAt(const String& str, const Integer& index) {
DEFINE_NATIVE_ENTRY(String_charAt, 2) {
const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Integer, index, arguments->NativeArgAt(1));
- uint32_t value = StringValueAt(receiver, index);
- ASSERT(value <= 0x10FFFF);
- return Symbols::FromCharCode(value);
+ uint16_t value = StringValueAt(receiver, index);
+ return Symbols::FromCharCode(static_cast<int32_t>(value));
}
+// Returns the 16-bit UTF-16 code unit at the given index.
DEFINE_NATIVE_ENTRY(String_codeUnitAt, 2) {
const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Integer, index, arguments->NativeArgAt(1));
-
- int32_t value = StringValueAt(receiver, index);
- ASSERT(value >= 0);
- ASSERT(value <= 0xFFFF);
- return Smi::New(value);
+ uint16_t value = StringValueAt(receiver, index);
+ return Smi::New(static_cast<intptr_t>(value));
}
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698