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

Side by Side Diff: src/conversions.cc

Issue 225823003: Implement handlified String::Equals and Name::Equals. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: refactored StringToDouble Created 6 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 | « src/conversions.h ('k') | src/factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // We cast to const uint8_t* here to avoid instantiating the 49 // We cast to const uint8_t* here to avoid instantiating the
50 // InternalStringToDouble() template for const char* as well. 50 // InternalStringToDouble() template for const char* as well.
51 const uint8_t* start = reinterpret_cast<const uint8_t*>(str); 51 const uint8_t* start = reinterpret_cast<const uint8_t*>(str);
52 const uint8_t* end = start + StrLength(str); 52 const uint8_t* end = start + StrLength(str);
53 return InternalStringToDouble(unicode_cache, start, end, flags, 53 return InternalStringToDouble(unicode_cache, start, end, flags,
54 empty_string_val); 54 empty_string_val);
55 } 55 }
56 56
57 57
58 double StringToDouble(UnicodeCache* unicode_cache, 58 double StringToDouble(UnicodeCache* unicode_cache,
59 Vector<const char> str, 59 Vector<const uint8_t> str,
60 int flags, 60 int flags,
61 double empty_string_val) { 61 double empty_string_val) {
62 // We cast to const uint8_t* here to avoid instantiating the 62 // We cast to const uint8_t* here to avoid instantiating the
63 // InternalStringToDouble() template for const char* as well. 63 // InternalStringToDouble() template for const char* as well.
64 const uint8_t* start = reinterpret_cast<const uint8_t*>(str.start()); 64 const uint8_t* start = reinterpret_cast<const uint8_t*>(str.start());
65 const uint8_t* end = start + str.length(); 65 const uint8_t* end = start + str.length();
66 return InternalStringToDouble(unicode_cache, start, end, flags, 66 return InternalStringToDouble(unicode_cache, start, end, flags,
67 empty_string_val); 67 empty_string_val);
68 } 68 }
69 69
70 70
71 double StringToDouble(UnicodeCache* unicode_cache, 71 double StringToDouble(UnicodeCache* unicode_cache,
72 Vector<const uc16> str, 72 Vector<const uc16> str,
73 int flags, 73 int flags,
74 double empty_string_val) { 74 double empty_string_val) {
75 const uc16* end = str.start() + str.length(); 75 const uc16* end = str.start() + str.length();
76 return InternalStringToDouble(unicode_cache, str.start(), end, flags, 76 return InternalStringToDouble(unicode_cache, str.start(), end, flags,
77 empty_string_val); 77 empty_string_val);
78 } 78 }
79 79
80 80
81 // Converts a string into an integer.
82 double StringToInt(UnicodeCache* unicode_cache,
83 Vector<const uint8_t> vector,
84 int radix) {
85 return InternalStringToInt(
86 unicode_cache, vector.start(), vector.start() + vector.length(), radix);
87 }
88
89
90 double StringToInt(UnicodeCache* unicode_cache,
91 Vector<const uc16> vector,
92 int radix) {
93 return InternalStringToInt(
94 unicode_cache, vector.start(), vector.start() + vector.length(), radix);
95 }
96
97
81 const char* DoubleToCString(double v, Vector<char> buffer) { 98 const char* DoubleToCString(double v, Vector<char> buffer) {
82 switch (fpclassify(v)) { 99 switch (fpclassify(v)) {
83 case FP_NAN: return "NaN"; 100 case FP_NAN: return "NaN";
84 case FP_INFINITE: return (v < 0.0 ? "-Infinity" : "Infinity"); 101 case FP_INFINITE: return (v < 0.0 ? "-Infinity" : "Infinity");
85 case FP_ZERO: return "0"; 102 case FP_ZERO: return "0";
86 default: { 103 default: {
87 SimpleStringBuilder builder(buffer.start(), buffer.length()); 104 SimpleStringBuilder builder(buffer.start(), buffer.length());
88 int decimal_point; 105 int decimal_point;
89 int sign; 106 int sign;
90 const int kV8DtoaBufferCapacity = kBase10MaximalLength + 1; 107 const int kV8DtoaBufferCapacity = kBase10MaximalLength + 1;
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 if (decimal_pos > 0) result_size++; 454 if (decimal_pos > 0) result_size++;
438 // Allocate result and fill in the parts. 455 // Allocate result and fill in the parts.
439 SimpleStringBuilder builder(result_size + 1); 456 SimpleStringBuilder builder(result_size + 1);
440 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); 457 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size);
441 if (decimal_pos > 0) builder.AddCharacter('.'); 458 if (decimal_pos > 0) builder.AddCharacter('.');
442 builder.AddSubstring(decimal_buffer, decimal_pos); 459 builder.AddSubstring(decimal_buffer, decimal_pos);
443 return builder.Finalize(); 460 return builder.Finalize();
444 } 461 }
445 462
446 } } // namespace v8::internal 463 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/conversions.h ('k') | src/factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698