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

Side by Side Diff: third_party/WebKit/Source/wtf/text/StringBuilder.cpp

Issue 2668903003: Replace WTF::emptyString{16Bit}() with a static global (Closed)
Patch Set: Replace WTF::emptyString{16Bit}() with a static global Created 3 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
OLDNEW
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 17 matching lines...) Expand all
28 28
29 #include "wtf/dtoa.h" 29 #include "wtf/dtoa.h"
30 #include "wtf/text/IntegerToStringConversion.h" 30 #include "wtf/text/IntegerToStringConversion.h"
31 #include "wtf/text/WTFString.h" 31 #include "wtf/text/WTFString.h"
32 #include <algorithm> 32 #include <algorithm>
33 33
34 namespace WTF { 34 namespace WTF {
35 35
36 String StringBuilder::toString() { 36 String StringBuilder::toString() {
37 if (!m_length) 37 if (!m_length)
38 return emptyString(); 38 return emptyString;
39 if (m_string.isNull()) { 39 if (m_string.isNull()) {
40 if (m_is8Bit) 40 if (m_is8Bit)
41 m_string = String(characters8(), m_length); 41 m_string = String(characters8(), m_length);
42 else 42 else
43 m_string = String(characters16(), m_length); 43 m_string = String(characters16(), m_length);
44 clearBuffer(); 44 clearBuffer();
45 } 45 }
46 return m_string; 46 return m_string;
47 } 47 }
48 48
49 AtomicString StringBuilder::toAtomicString() { 49 AtomicString StringBuilder::toAtomicString() {
50 if (!m_length) 50 if (!m_length)
51 return emptyAtom; 51 return emptyAtom;
52 if (m_string.isNull()) { 52 if (m_string.isNull()) {
53 if (m_is8Bit) 53 if (m_is8Bit)
54 m_string = AtomicString(characters8(), m_length); 54 m_string = AtomicString(characters8(), m_length);
55 else 55 else
56 m_string = AtomicString(characters16(), m_length); 56 m_string = AtomicString(characters16(), m_length);
57 clearBuffer(); 57 clearBuffer();
58 } 58 }
59 return AtomicString(m_string); 59 return AtomicString(m_string);
60 } 60 }
61 61
62 String StringBuilder::substring(unsigned start, unsigned length) const { 62 String StringBuilder::substring(unsigned start, unsigned length) const {
63 if (start >= m_length) 63 if (start >= m_length)
64 return emptyString(); 64 return emptyString;
65 if (!m_string.isNull()) 65 if (!m_string.isNull())
66 return m_string.substring(start, length); 66 return m_string.substring(start, length);
67 length = std::min(length, m_length - start); 67 length = std::min(length, m_length - start);
68 if (m_is8Bit) 68 if (m_is8Bit)
69 return String(characters8() + start, length); 69 return String(characters8() + start, length);
70 return String(characters16() + start, length); 70 return String(characters16() + start, length);
71 } 71 }
72 72
73 void StringBuilder::swap(StringBuilder& builder) { 73 void StringBuilder::swap(StringBuilder& builder) {
74 std::swap(m_string, builder.m_string); 74 std::swap(m_string, builder.m_string);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 void StringBuilder::appendNumber(unsigned long long number) { 224 void StringBuilder::appendNumber(unsigned long long number) {
225 appendIntegerInternal(*this, number); 225 appendIntegerInternal(*this, number);
226 } 226 }
227 227
228 void StringBuilder::appendNumber(double number, unsigned precision) { 228 void StringBuilder::appendNumber(double number, unsigned precision) {
229 NumberToStringBuffer buffer; 229 NumberToStringBuffer buffer;
230 append(numberToFixedPrecisionString(number, precision, buffer)); 230 append(numberToFixedPrecisionString(number, precision, buffer));
231 } 231 }
232 232
233 } // namespace WTF 233 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/tests/KeyboardTest.cpp ('k') | third_party/WebKit/Source/wtf/text/StringBuilderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698