OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 11 matching lines...) Expand all Loading... | |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 #include "StringBuilder.h" | 28 #include "StringBuilder.h" |
29 | 29 |
30 #include "IntegerToStringConversion.h" | 30 #include "IntegerToStringConversion.h" |
31 #include "WTFString.h" | 31 #include "WTFString.h" |
32 #include "wtf/dtoa.h" | |
32 | 33 |
33 namespace WTF { | 34 namespace WTF { |
34 | 35 |
35 static unsigned expandedCapacity(unsigned capacity, unsigned requiredLength) | 36 static unsigned expandedCapacity(unsigned capacity, unsigned requiredLength) |
36 { | 37 { |
37 static const unsigned minimumCapacity = 16; | 38 static const unsigned minimumCapacity = 16; |
38 return std::max(requiredLength, std::max(minimumCapacity, capacity * 2)); | 39 return std::max(requiredLength, std::max(minimumCapacity, capacity * 2)); |
39 } | 40 } |
40 | 41 |
41 void StringBuilder::reifyString() | 42 void StringBuilder::reifyString() |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 void StringBuilder::appendNumber(long long number) | 340 void StringBuilder::appendNumber(long long number) |
340 { | 341 { |
341 numberToStringSigned<StringBuilder>(number, this); | 342 numberToStringSigned<StringBuilder>(number, this); |
342 } | 343 } |
343 | 344 |
344 void StringBuilder::appendNumber(unsigned long long number) | 345 void StringBuilder::appendNumber(unsigned long long number) |
345 { | 346 { |
346 numberToStringUnsigned<StringBuilder>(number, this); | 347 numberToStringUnsigned<StringBuilder>(number, this); |
347 } | 348 } |
348 | 349 |
350 void StringBuilder::appendNumber(double number, unsigned precision, TrailingZero sTruncatingPolicy trailingZerosTruncatingPolicy) | |
351 { | |
352 NumberToStringBuffer buffer; | |
353 append(numberToFixedPrecisionString(number, precision, buffer, trailingZeros TruncatingPolicy == TruncateTrailingZeros)); | |
abarth-chromium
2014/03/26 16:52:31
This can be made more efficient. You're creating
| |
354 } | |
355 | |
349 bool StringBuilder::canShrink() const | 356 bool StringBuilder::canShrink() const |
350 { | 357 { |
351 // Only shrink the buffer if it's less than 80% full. Need to tune this heur istic! | 358 // Only shrink the buffer if it's less than 80% full. Need to tune this heur istic! |
352 return m_buffer && m_buffer->length() > (m_length + (m_length >> 2)); | 359 return m_buffer && m_buffer->length() > (m_length + (m_length >> 2)); |
353 } | 360 } |
354 | 361 |
355 void StringBuilder::shrinkToFit() | 362 void StringBuilder::shrinkToFit() |
356 { | 363 { |
357 if (!canShrink()) | 364 if (!canShrink()) |
358 return; | 365 return; |
359 if (m_is8Bit) | 366 if (m_is8Bit) |
360 reallocateBuffer<LChar>(m_length); | 367 reallocateBuffer<LChar>(m_length); |
361 else | 368 else |
362 reallocateBuffer<UChar>(m_length); | 369 reallocateBuffer<UChar>(m_length); |
363 m_string = m_buffer.release(); | 370 m_string = m_buffer.release(); |
364 } | 371 } |
365 | 372 |
366 } // namespace WTF | 373 } // namespace WTF |
OLD | NEW |