2 * Copyright (C) 2004-2008, 2013-2014 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
4 * Copyright (C) 2012 Google Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
24 #include "AtomicString.h"
26 #include "IntegerToStringConversion.h"
35 AtomicString AtomicString::lower() const
37 // Note: This is a hot function in the Dromaeo benchmark.
38 StringImpl* impl = this->impl();
40 return AtomicString();
42 RefPtr<StringImpl> lowercasedString = impl->lower();
43 if (LIKELY(lowercasedString == impl))
47 result.m_string = AtomicStringImpl::add(lowercasedString.get());
51 template<AtomicString::CaseConvertType type>
52 ALWAYS_INLINE AtomicString AtomicString::convertASCIICase() const
54 StringImpl* impl = this->impl();
56 return AtomicString();
58 // Convert short strings without allocating a new StringImpl, since
59 // there's a good chance these strings are already in the atomic
60 // string table and so no memory allocation will be required.
62 const unsigned localBufferSize = 100;
63 if (impl->is8Bit() && (length = impl->length()) <= localBufferSize) {
64 const LChar* characters = impl->characters8();
65 unsigned failingIndex;
66 for (unsigned i = 0; i < length; ++i) {
67 if (type == CaseConvertType::Lower ? UNLIKELY(isASCIIUpper(characters[i])) : LIKELY(isASCIILower(characters[i]))) {
74 LChar localBuffer[localBufferSize];
75 for (unsigned i = 0; i < failingIndex; ++i)
76 localBuffer[i] = characters[i];
77 for (unsigned i = failingIndex; i < length; ++i)
78 localBuffer[i] = type == CaseConvertType::Lower ? toASCIILower(characters[i]) : toASCIIUpper(characters[i]);
79 return AtomicString(localBuffer, length);
82 Ref<StringImpl> convertedString = type == CaseConvertType::Lower ? impl->convertToASCIILowercase() : impl->convertToASCIIUppercase();
83 if (LIKELY(convertedString.ptr() == impl))
87 result.m_string = AtomicStringImpl::add(convertedString.ptr());
91 AtomicString AtomicString::convertToASCIILowercase() const
93 return convertASCIICase<CaseConvertType::Lower>();
96 AtomicString AtomicString::convertToASCIIUppercase() const
98 return convertASCIICase<CaseConvertType::Upper>();
101 AtomicString AtomicString::number(int number)
103 return numberToStringSigned<AtomicString>(number);
106 AtomicString AtomicString::number(unsigned number)
108 return numberToStringUnsigned<AtomicString>(number);
111 AtomicString AtomicString::number(double number)
113 NumberToStringBuffer buffer;
114 return String(numberToFixedPrecisionString(number, 6, buffer, true));
117 AtomicString AtomicString::fromUTF8Internal(const char* charactersStart, const char* charactersEnd)
119 auto impl = AtomicStringImpl::addUTF8(charactersStart, charactersEnd);
126 void AtomicString::show() const