OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights |
4 * reserved. | 4 * reserved. |
5 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 5 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return; | 96 return; |
97 } | 97 } |
98 | 98 |
99 // FIXME: This is extremely inefficient. So much so that we might want to | 99 // FIXME: This is extremely inefficient. So much so that we might want to |
100 // take this out of String's API. We can make it better by optimizing the | 100 // take this out of String's API. We can make it better by optimizing the |
101 // case where exactly one String is pointing at this StringImpl, but even | 101 // case where exactly one String is pointing at this StringImpl, but even |
102 // then it's going to require a call into the allocator every single time. | 102 // then it's going to require a call into the allocator every single time. |
103 | 103 |
104 if (impl_->Is8Bit() && string.Is8Bit()) { | 104 if (impl_->Is8Bit() && string.Is8Bit()) { |
105 LChar* data; | 105 LChar* data; |
106 RELEASE_ASSERT(string.length() <= | 106 CHECK_LE(string.length(), |
107 std::numeric_limits<unsigned>::max() - impl_->length()); | 107 std::numeric_limits<unsigned>::max() - impl_->length()); |
108 RefPtr<StringImpl> new_impl = StringImpl::CreateUninitialized( | 108 RefPtr<StringImpl> new_impl = StringImpl::CreateUninitialized( |
109 impl_->length() + string.length(), data); | 109 impl_->length() + string.length(), data); |
110 memcpy(data, impl_->Characters8(), impl_->length() * sizeof(LChar)); | 110 memcpy(data, impl_->Characters8(), impl_->length() * sizeof(LChar)); |
111 memcpy(data + impl_->length(), string.Characters8(), | 111 memcpy(data + impl_->length(), string.Characters8(), |
112 string.length() * sizeof(LChar)); | 112 string.length() * sizeof(LChar)); |
113 impl_ = new_impl.Release(); | 113 impl_ = new_impl.Release(); |
114 return; | 114 return; |
115 } | 115 } |
116 | 116 |
117 UChar* data; | 117 UChar* data; |
118 RELEASE_ASSERT(string.length() <= | 118 CHECK_LE(string.length(), |
119 std::numeric_limits<unsigned>::max() - impl_->length()); | 119 std::numeric_limits<unsigned>::max() - impl_->length()); |
120 RefPtr<StringImpl> new_impl = | 120 RefPtr<StringImpl> new_impl = |
121 StringImpl::CreateUninitialized(impl_->length() + string.length(), data); | 121 StringImpl::CreateUninitialized(impl_->length() + string.length(), data); |
122 | 122 |
123 if (impl_->Is8Bit()) | 123 if (impl_->Is8Bit()) |
124 StringImpl::CopyChars(data, impl_->Characters8(), impl_->length()); | 124 StringImpl::CopyChars(data, impl_->Characters8(), impl_->length()); |
125 else | 125 else |
126 StringImpl::CopyChars(data, impl_->Characters16(), impl_->length()); | 126 StringImpl::CopyChars(data, impl_->Characters16(), impl_->length()); |
127 | 127 |
128 if (string.Is8Bit()) | 128 if (string.Is8Bit()) |
129 StringImpl::CopyChars(data + impl_->length(), string.Characters8(), | 129 StringImpl::CopyChars(data + impl_->length(), string.Characters8(), |
(...skipping 11 matching lines...) Expand all Loading... |
141 // take this out of String's API. We can make it better by optimizing the | 141 // take this out of String's API. We can make it better by optimizing the |
142 // case where exactly one String is pointing at this StringImpl, but even | 142 // case where exactly one String is pointing at this StringImpl, but even |
143 // then it's going to require a call into the allocator every single time. | 143 // then it's going to require a call into the allocator every single time. |
144 if (!impl_) { | 144 if (!impl_) { |
145 impl_ = StringImpl::Create(&c, 1); | 145 impl_ = StringImpl::Create(&c, 1); |
146 return; | 146 return; |
147 } | 147 } |
148 | 148 |
149 // FIXME: We should be able to create an 8 bit string via this code path. | 149 // FIXME: We should be able to create an 8 bit string via this code path. |
150 UChar* data; | 150 UChar* data; |
151 RELEASE_ASSERT(impl_->length() < std::numeric_limits<unsigned>::max()); | 151 CHECK_LT(impl_->length(), std::numeric_limits<unsigned>::max()); |
152 RefPtr<StringImpl> new_impl = | 152 RefPtr<StringImpl> new_impl = |
153 StringImpl::CreateUninitialized(impl_->length() + 1, data); | 153 StringImpl::CreateUninitialized(impl_->length() + 1, data); |
154 if (impl_->Is8Bit()) | 154 if (impl_->Is8Bit()) |
155 StringImpl::CopyChars(data, impl_->Characters8(), impl_->length()); | 155 StringImpl::CopyChars(data, impl_->Characters8(), impl_->length()); |
156 else | 156 else |
157 StringImpl::CopyChars(data, impl_->Characters16(), impl_->length()); | 157 StringImpl::CopyChars(data, impl_->Characters16(), impl_->length()); |
158 data[impl_->length()] = c; | 158 data[impl_->length()] = c; |
159 impl_ = new_impl.Release(); | 159 impl_ = new_impl.Release(); |
160 } | 160 } |
161 | 161 |
(...skipping 17 matching lines...) Expand all Loading... |
179 template <typename CharType> | 179 template <typename CharType> |
180 PassRefPtr<StringImpl> InsertInternal(PassRefPtr<StringImpl> impl, | 180 PassRefPtr<StringImpl> InsertInternal(PassRefPtr<StringImpl> impl, |
181 const CharType* characters_to_insert, | 181 const CharType* characters_to_insert, |
182 unsigned length_to_insert, | 182 unsigned length_to_insert, |
183 unsigned position) { | 183 unsigned position) { |
184 if (!length_to_insert) | 184 if (!length_to_insert) |
185 return impl; | 185 return impl; |
186 | 186 |
187 DCHECK(characters_to_insert); | 187 DCHECK(characters_to_insert); |
188 UChar* data; // FIXME: We should be able to create an 8 bit string here. | 188 UChar* data; // FIXME: We should be able to create an 8 bit string here. |
189 RELEASE_ASSERT(length_to_insert <= | 189 CHECK_LE(length_to_insert, |
190 std::numeric_limits<unsigned>::max() - impl->length()); | 190 std::numeric_limits<unsigned>::max() - impl->length()); |
191 RefPtr<StringImpl> new_impl = | 191 RefPtr<StringImpl> new_impl = |
192 StringImpl::CreateUninitialized(impl->length() + length_to_insert, data); | 192 StringImpl::CreateUninitialized(impl->length() + length_to_insert, data); |
193 | 193 |
194 if (impl->Is8Bit()) | 194 if (impl->Is8Bit()) |
195 StringImpl::CopyChars(data, impl->Characters8(), position); | 195 StringImpl::CopyChars(data, impl->Characters8(), position); |
196 else | 196 else |
197 StringImpl::CopyChars(data, impl->Characters16(), position); | 197 StringImpl::CopyChars(data, impl->Characters16(), position); |
198 | 198 |
199 StringImpl::CopyChars(data + position, characters_to_insert, | 199 StringImpl::CopyChars(data + position, characters_to_insert, |
200 length_to_insert); | 200 length_to_insert); |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 | 732 |
733 UChar* destination; | 733 UChar* destination; |
734 String result = String::CreateUninitialized(length, destination); | 734 String result = String::CreateUninitialized(length, destination); |
735 | 735 |
736 StringImpl::CopyChars(destination, source, length); | 736 StringImpl::CopyChars(destination, source, length); |
737 | 737 |
738 return result; | 738 return result; |
739 } | 739 } |
740 | 740 |
741 String String::FromUTF8(const LChar* string_start, size_t length) { | 741 String String::FromUTF8(const LChar* string_start, size_t length) { |
742 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max()); | 742 CHECK_LE(length, std::numeric_limits<unsigned>::max()); |
743 | 743 |
744 if (!string_start) | 744 if (!string_start) |
745 return String(); | 745 return String(); |
746 | 746 |
747 if (!length) | 747 if (!length) |
748 return g_empty_string; | 748 return g_empty_string; |
749 | 749 |
750 if (CharactersAreAllASCII(string_start, length)) | 750 if (CharactersAreAllASCII(string_start, length)) |
751 return StringImpl::Create(string_start, length); | 751 return StringImpl::Create(string_start, length); |
752 | 752 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 return out << '"'; | 824 return out << '"'; |
825 } | 825 } |
826 | 826 |
827 #ifndef NDEBUG | 827 #ifndef NDEBUG |
828 void String::Show() const { | 828 void String::Show() const { |
829 DataLogF("%s\n", AsciiDebug(Impl()).data()); | 829 DataLogF("%s\n", AsciiDebug(Impl()).data()); |
830 } | 830 } |
831 #endif | 831 #endif |
832 | 832 |
833 } // namespace WTF | 833 } // namespace WTF |
OLD | NEW |