| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 103 | 103 | 
| 104   if (impl_->Is8Bit() && string.Is8Bit()) { | 104   if (impl_->Is8Bit() && string.Is8Bit()) { | 
| 105     LChar* data; | 105     LChar* data; | 
| 106     CHECK_LE(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_ = std::move(new_impl); | 
| 114     return; | 114     return; | 
| 115   } | 115   } | 
| 116 | 116 | 
| 117   UChar* data; | 117   UChar* data; | 
| 118   CHECK_LE(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(), | 
| 130                           string.length()); | 130                           string.length()); | 
| 131   else | 131   else | 
| 132     StringImpl::CopyChars(data + impl_->length(), string.Characters16(), | 132     StringImpl::CopyChars(data + impl_->length(), string.Characters16(), | 
| 133                           string.length()); | 133                           string.length()); | 
| 134 | 134 | 
| 135   impl_ = new_impl.Release(); | 135   impl_ = std::move(new_impl); | 
| 136 } | 136 } | 
| 137 | 137 | 
| 138 template <typename CharacterType> | 138 template <typename CharacterType> | 
| 139 inline void String::AppendInternal(CharacterType c) { | 139 inline void String::AppendInternal(CharacterType c) { | 
| 140   // FIXME: This is extremely inefficient. So much so that we might want to | 140   // FIXME: This is extremely inefficient. So much so that we might want to | 
| 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   CHECK_LT(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_ = std::move(new_impl); | 
| 160 } | 160 } | 
| 161 | 161 | 
| 162 void String::append(LChar c) { | 162 void String::append(LChar c) { | 
| 163   AppendInternal(c); | 163   AppendInternal(c); | 
| 164 } | 164 } | 
| 165 | 165 | 
| 166 void String::append(UChar c) { | 166 void String::append(UChar c) { | 
| 167   AppendInternal(c); | 167   AppendInternal(c); | 
| 168 } | 168 } | 
| 169 | 169 | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 223   if (position >= length()) { | 223   if (position >= length()) { | 
| 224     if (string.Is8Bit()) | 224     if (string.Is8Bit()) | 
| 225       append(string); | 225       append(string); | 
| 226     else | 226     else | 
| 227       append(string); | 227       append(string); | 
| 228     return; | 228     return; | 
| 229   } | 229   } | 
| 230 | 230 | 
| 231   DCHECK(impl_); | 231   DCHECK(impl_); | 
| 232   if (string.Is8Bit()) | 232   if (string.Is8Bit()) | 
| 233     impl_ = InsertInternal(impl_.Release(), string.Characters8(), | 233     impl_ = InsertInternal(std::move(impl_), string.Characters8(), | 
| 234                            string.length(), position); | 234                            string.length(), position); | 
| 235   else | 235   else | 
| 236     impl_ = InsertInternal(impl_.Release(), string.Characters16(), | 236     impl_ = InsertInternal(std::move(impl_), string.Characters16(), | 
| 237                            string.length(), position); | 237                            string.length(), position); | 
| 238 } | 238 } | 
| 239 | 239 | 
| 240 UChar32 String::CharacterStartingAt(unsigned i) const { | 240 UChar32 String::CharacterStartingAt(unsigned i) const { | 
| 241   if (!impl_ || i >= impl_->length()) | 241   if (!impl_ || i >= impl_->length()) | 
| 242     return 0; | 242     return 0; | 
| 243   return impl_->CharacterStartingAt(i); | 243   return impl_->CharacterStartingAt(i); | 
| 244 } | 244 } | 
| 245 | 245 | 
| 246 void String::Ensure16Bit() { | 246 void String::Ensure16Bit() { | 
| (...skipping 577 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 | 
|---|