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

Unified Diff: runtime/vm/object.cc

Issue 368483004: Avoid unnecessary copying when parsing doubles. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 6 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
« runtime/lib/string_patch.dart ('K') | « runtime/vm/object.h ('k') | 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 3893ccb6ef22ee4ca4c9cae0313d870536245a70..bfb2bee526da27b765743d34ee1e8aa6277bf191 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -16907,6 +16907,35 @@ RawString* String::ToLowerCase(const String& str, Heap::Space space) {
return Transform(CaseMapping::ToLower, str, space);
}
+bool String::ParseDouble(const String& str,
+ intptr_t start, intptr_t end,
+ double* result) {
+ ASSERT(0 <= start);
+ ASSERT(start <= end);
+ ASSERT(end <= str.Length());
+ int length = end - start;
Ivan Posva 2014/07/03 19:44:14 Please always use intptr_t.
Lasse Reichstein Nielsen 2014/07/04 06:46:01 Ack, yes. Will do.
+ NoGCScope no_gc;
+ const uint8_t* startChar;
+ if (str.IsOneByteString()) {
+ startChar = OneByteString::CharAddr(str, start);
+ } else if (str.IsExternalOneByteString()) {
+ startChar = ExternalOneByteString::CharAddr(str, start);
+ } else {
+ uint8_t* chars = Isolate::Current()->current_zone()->Alloc<uint8_t>(length);
+ for (int i = 0; i < length; i++) {
Ivan Posva 2014/07/03 19:44:14 intptr_t
+ int ch = str.CharAt(start + i);
Ivan Posva 2014/07/03 19:44:14 The return type of CharAt is int32_t. Also it wou
Lasse Reichstein Nielsen 2014/07/04 06:46:01 Will do. Didn't know about the CharAtFunc - nice!
+ if (ch < 128) {
+ chars[i] = ch;
+ } else {
+ return false; // Not ASCII, so definitely not valid double numeral.
+ }
+ }
+ startChar = chars;
+ }
+ return CStringToDouble(reinterpret_cast<const char*>(startChar),
+ length, result);
+}
+
// Check to see if 'str1' matches 'str2' as is or
// once the private key separator is stripped from str2.
« runtime/lib/string_patch.dart ('K') | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698