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

Side by Side Diff: runtime/lib/integers.cc

Issue 14064019: Allow leading + when parsing integers in fast case (it is allowed per library implementation, only … (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/native_entry.h" 10 #include "vm/native_entry.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 183
184 DEFINE_NATIVE_ENTRY(Integer_parse, 1) { 184 DEFINE_NATIVE_ENTRY(Integer_parse, 1) {
185 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); 185 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0));
186 if (value.IsOneByteString()) { 186 if (value.IsOneByteString()) {
187 // Quick conversion for unpadded integers in strings. 187 // Quick conversion for unpadded integers in strings.
188 const intptr_t len = value.Length(); 188 const intptr_t len = value.Length();
189 if (len > 0) { 189 if (len > 0) {
190 const char* cstr = value.ToCString(); 190 const char* cstr = value.ToCString();
191 ASSERT(cstr != NULL); 191 ASSERT(cstr != NULL);
192 // Dart differences from strtol: 192 char* p_end = NULL;
193 // a) '+5' is not a valid integer (leading plus). 193 const int64_t int_value = strtoll(cstr, &p_end, 10);
194 if (cstr[0] != '+') { 194 if (p_end == (cstr + len)) {
195 char* p_end = NULL; 195 if ((int_value != LLONG_MIN) && (int_value != LLONG_MAX)) {
196 const int64_t int_value = strtoll(cstr, &p_end, 10); 196 return Integer::New(int_value);
197 if (p_end == (cstr + len)) {
198 if ((int_value != LLONG_MIN) && (int_value != LLONG_MAX)) {
199 return Integer::New(int_value);
200 }
201 } 197 }
202 } 198 }
203 } 199 }
204 } 200 }
205 201
206 Scanner scanner(value, Symbols::Empty()); 202 Scanner scanner(value, Symbols::Empty());
207 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); 203 const Scanner::GrowableTokenStream& tokens = scanner.GetStream();
208 String* int_string; 204 String* int_string;
209 bool is_positive; 205 bool is_positive;
210 if (Scanner::IsValidLiteral(tokens, 206 if (Scanner::IsValidLiteral(tokens,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 320
325 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) { 321 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) {
326 const Bigint& value = Bigint::CheckedHandle(arguments->NativeArgAt(0)); 322 const Bigint& value = Bigint::CheckedHandle(arguments->NativeArgAt(0));
327 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value)); 323 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value));
328 ASSERT(CheckInteger(value)); 324 ASSERT(CheckInteger(value));
329 ASSERT(CheckInteger(result)); 325 ASSERT(CheckInteger(result));
330 return result.AsValidInteger(); 326 return result.AsValidInteger();
331 } 327 }
332 328
333 } // namespace dart 329 } // namespace dart
OLDNEW
« 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