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

Side by Side Diff: src/strtod.cc

Issue 4168002: Don't create empty vectors using SubVector. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 10 years, 1 month 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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 return gay_strtod(gay_buffer, NULL); 121 return gay_strtod(gay_buffer, NULL);
122 } 122 }
123 123
124 124
125 static Vector<const char> TrimLeadingZeros(Vector<const char> buffer) { 125 static Vector<const char> TrimLeadingZeros(Vector<const char> buffer) {
126 for (int i = 0; i < buffer.length(); i++) { 126 for (int i = 0; i < buffer.length(); i++) {
127 if (buffer[i] != '0') { 127 if (buffer[i] != '0') {
128 return buffer.SubVector(i, buffer.length()); 128 return buffer.SubVector(i, buffer.length());
129 } 129 }
130 } 130 }
131 return buffer.SubVector(0, 0); 131 return Vector<const char>(buffer.start(), 0);
132 } 132 }
133 133
134 134
135 static Vector<const char> TrimTrailingZeros(Vector<const char> buffer) { 135 static Vector<const char> TrimTrailingZeros(Vector<const char> buffer) {
136 for (int i = buffer.length() - 1; i >= 0; --i) { 136 for (int i = buffer.length() - 1; i >= 0; --i) {
137 if (buffer[i] != '0') { 137 if (buffer[i] != '0') {
138 return buffer.SubVector(0, i + 1); 138 return buffer.SubVector(0, i + 1);
139 } 139 }
140 } 140 }
141 return buffer.SubVector(0, 0); 141 return Vector<const char>(buffer.start(), 0);
142 } 142 }
143 143
144 144
145 // Reads digits from the buffer and converts them to a uint64. 145 // Reads digits from the buffer and converts them to a uint64.
146 // Reads in as many digits as fit into a uint64. 146 // Reads in as many digits as fit into a uint64.
147 // When the string starts with "1844674407370955161" no further digit is read. 147 // When the string starts with "1844674407370955161" no further digit is read.
148 // Since 2^64 = 18446744073709551616 it would still be possible read another 148 // Since 2^64 = 18446744073709551616 it would still be possible read another
149 // digit if it was less or equal than 6, but this would complicate the code. 149 // digit if it was less or equal than 6, but this would complicate the code.
150 static uint64_t ReadUint64(Vector<const char> buffer, 150 static uint64_t ReadUint64(Vector<const char> buffer,
151 int* number_of_read_digits) { 151 int* number_of_read_digits) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 384
385 double result; 385 double result;
386 if (DoubleStrtod(trimmed, exponent, &result) || 386 if (DoubleStrtod(trimmed, exponent, &result) ||
387 DiyFpStrtod(trimmed, exponent, &result)) { 387 DiyFpStrtod(trimmed, exponent, &result)) {
388 return result; 388 return result;
389 } 389 }
390 return old_strtod(trimmed, exponent); 390 return old_strtod(trimmed, exponent);
391 } 391 }
392 392
393 } } // namespace v8::internal 393 } } // namespace v8::internal
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