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

Unified Diff: runtime/lib/integers.cc

Issue 12328068: Improve perfromance of integer parsing for Smi-s. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/integers.cc
===================================================================
--- runtime/lib/integers.cc (revision 18983)
+++ runtime/lib/integers.cc (working copy)
@@ -183,6 +183,26 @@
DEFINE_NATIVE_ENTRY(Integer_parse, 1) {
GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0));
+ if (value.IsOneByteString()) {
+ // Quick conversion for unpadded integers in strings.
+ const intptr_t len = value.Length();
+ if (len > 0) {
+ const char* cstr = value.ToCString();
+ ASSERT(cstr != NULL);
+ // Dart differences from strtol:
+ // a) '+5' is not a valid integer (leading plus).
+ if (cstr[0] != '+') {
+ char* p_end = NULL;
+ const int64_t int_value = strtol(cstr, &p_end, 10);
+ if (p_end == (cstr + len)) {
+ if ((Smi::kMinValue <= int_value) && (int_value <= Smi::kMaxValue)) {
+ return Smi::New(int_value);
+ }
+ }
+ }
+ }
+ }
+
Scanner scanner(value, Symbols::Empty());
const Scanner::GrowableTokenStream& tokens = scanner.GetStream();
String* int_string;
« 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