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

Side by Side Diff: src/conversions.cc

Issue 619005: Fast algorithm for double->string conversion. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/checks.h ('k') | src/diy_fp.h » ('j') | src/diy_fp.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <stdarg.h> 28 #include <stdarg.h>
29 29
30 #include "v8.h" 30 #include "v8.h"
31 31
32 #include "conversions-inl.h" 32 #include "conversions-inl.h"
33 #include "factory.h" 33 #include "factory.h"
34 #include "scanner.h" 34 #include "scanner.h"
35 35
36 #include "grisu3.h"
37
36 namespace v8 { 38 namespace v8 {
37 namespace internal { 39 namespace internal {
38 40
39 int HexValue(uc32 c) { 41 int HexValue(uc32 c) {
40 if ('0' <= c && c <= '9') 42 if ('0' <= c && c <= '9')
41 return c - '0'; 43 return c - '0';
42 if ('a' <= c && c <= 'f') 44 if ('a' <= c && c <= 'f')
43 return c - 'a' + 10; 45 return c - 'a' + 10;
44 if ('A' <= c && c <= 'F') 46 if ('A' <= c && c <= 'F')
45 return c - 'A' + 10; 47 return c - 'A' + 10;
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 break; 377 break;
376 378
377 case FP_ZERO: 379 case FP_ZERO:
378 builder.AddCharacter('0'); 380 builder.AddCharacter('0');
379 break; 381 break;
380 382
381 default: { 383 default: {
382 int decimal_point; 384 int decimal_point;
383 int sign; 385 int sign;
384 386
385 char* decimal_rep = dtoa(v, 0, 0, &decimal_point, &sign, NULL); 387 char* decimal_rep;
386 int length = StrLength(decimal_rep); 388 bool used_dtoa = false;
389 char grisu_buffer[kGrisu3MaximalLength + 1];
390 int length;
391 if (grisu3(v, grisu_buffer, &sign, &length, &decimal_point)) {
392 decimal_rep = &grisu_buffer[0];
fschneider 2010/02/22 16:25:24 You can just write: decimal_rep = grisu_buffer;
Florian Loitsch 2010/02/23 09:05:10 Done.
393 } else {
394 decimal_rep = dtoa(v, 0, 0, &decimal_point, &sign, NULL);
395 used_dtoa = true;
396 length = StrLength(decimal_rep);
397 }
387 398
388 if (sign) builder.AddCharacter('-'); 399 if (sign) builder.AddCharacter('-');
389 400
390 if (length <= decimal_point && decimal_point <= 21) { 401 if (length <= decimal_point && decimal_point <= 21) {
391 // ECMA-262 section 9.8.1 step 6. 402 // ECMA-262 section 9.8.1 step 6.
392 builder.AddString(decimal_rep); 403 builder.AddString(decimal_rep);
393 builder.AddPadding('0', decimal_point - length); 404 builder.AddPadding('0', decimal_point - length);
394 405
395 } else if (0 < decimal_point && decimal_point <= 21) { 406 } else if (0 < decimal_point && decimal_point <= 21) {
396 // ECMA-262 section 9.8.1 step 7. 407 // ECMA-262 section 9.8.1 step 7.
(...skipping 14 matching lines...) Expand all
411 builder.AddCharacter('.'); 422 builder.AddCharacter('.');
412 builder.AddString(decimal_rep + 1); 423 builder.AddString(decimal_rep + 1);
413 } 424 }
414 builder.AddCharacter('e'); 425 builder.AddCharacter('e');
415 builder.AddCharacter((decimal_point >= 0) ? '+' : '-'); 426 builder.AddCharacter((decimal_point >= 0) ? '+' : '-');
416 int exponent = decimal_point - 1; 427 int exponent = decimal_point - 1;
417 if (exponent < 0) exponent = -exponent; 428 if (exponent < 0) exponent = -exponent;
418 builder.AddFormatted("%d", exponent); 429 builder.AddFormatted("%d", exponent);
419 } 430 }
420 431
421 freedtoa(decimal_rep); 432 if (used_dtoa) freedtoa(decimal_rep);
422 } 433 }
423 } 434 }
424 return builder.Finalize(); 435 return builder.Finalize();
425 } 436 }
426 437
427 438
428 const char* IntToCString(int n, Vector<char> buffer) { 439 const char* IntToCString(int n, Vector<char> buffer) {
429 bool negative = false; 440 bool negative = false;
430 if (n < 0) { 441 if (n < 0) {
431 // We must not negate the most negative int. 442 // We must not negate the most negative int.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 // Allocate result and fill in the parts. 711 // Allocate result and fill in the parts.
701 StringBuilder builder(result_size + 1); 712 StringBuilder builder(result_size + 1);
702 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); 713 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size);
703 if (decimal_pos > 0) builder.AddCharacter('.'); 714 if (decimal_pos > 0) builder.AddCharacter('.');
704 builder.AddSubstring(decimal_buffer, decimal_pos); 715 builder.AddSubstring(decimal_buffer, decimal_pos);
705 return builder.Finalize(); 716 return builder.Finalize();
706 } 717 }
707 718
708 719
709 } } // namespace v8::internal 720 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/checks.h ('k') | src/diy_fp.h » ('j') | src/diy_fp.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698