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

Side by Side Diff: Source/wtf/text/StringImpl.h

Issue 210013002: Rely on 'memcpy' in WTF::copyChars (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved.
4 * Copyright (C) 2009 Google Inc. All rights reserved. 4 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 291 }
292 292
293 static StringImpl* empty(); 293 static StringImpl* empty();
294 294
295 // FIXME: Does this really belong in StringImpl? 295 // FIXME: Does this really belong in StringImpl?
296 template <typename T> static void copyChars(T* destination, const T* source, unsigned numCharacters) 296 template <typename T> static void copyChars(T* destination, const T* source, unsigned numCharacters)
297 { 297 {
298 if (numCharacters == 1) { 298 if (numCharacters == 1) {
299 *destination = *source; 299 *destination = *source;
300 return; 300 return;
301 } 301 }
abarth-chromium 2014/03/24 16:46:54 Should we remove this branch too?
Mikhail 2014/03/25 10:30:26 This makes a bit better assembly, on the other han
302 302
303 // FIXME: Is this implementation really faster than memcpy? 303 memcpy(destination, source, numCharacters * sizeof(T));
304 if (numCharacters <= s_copyCharsInlineCutOff) {
305 unsigned i = 0;
306 #if (CPU(X86) || CPU(X86_64))
307 const unsigned charsPerInt = sizeof(uint32_t) / sizeof(T);
308
309 if (numCharacters > charsPerInt) {
310 unsigned stopCount = numCharacters & ~(charsPerInt - 1);
311
312 const uint32_t* srcCharacters = reinterpret_cast<const uint32_t* >(source);
313 uint32_t* destCharacters = reinterpret_cast<uint32_t*>(destinati on);
314 for (unsigned j = 0; i < stopCount; i += charsPerInt, ++j)
315 destCharacters[j] = srcCharacters[j];
316 }
317 #endif
318 for (; i < numCharacters; ++i)
319 destination[i] = source[i];
320 } else
321 memcpy(destination, source, numCharacters * sizeof(T));
322 } 304 }
323 305
324 ALWAYS_INLINE static void copyChars(UChar* destination, const LChar* source, unsigned numCharacters) 306 ALWAYS_INLINE static void copyChars(UChar* destination, const LChar* source, unsigned numCharacters)
325 { 307 {
326 for (unsigned i = 0; i < numCharacters; ++i) 308 for (unsigned i = 0; i < numCharacters; ++i)
327 destination[i] = source[i]; 309 destination[i] = source[i];
328 } 310 }
329 311
330 // Some string features, like refcounting and the atomicity flag, are not 312 // Some string features, like refcounting and the atomicity flag, are not
331 // thread-safe. We achieve thread safety by isolation, giving each thread 313 // thread-safe. We achieve thread safety by isolation, giving each thread
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 ALWAYS_INLINE static StringStats& stringStats() { return m_stringStats; } 415 ALWAYS_INLINE static StringStats& stringStats() { return m_stringStats; }
434 #endif 416 #endif
435 417
436 private: 418 private:
437 template<typename CharType> static size_t allocationSize(unsigned length) 419 template<typename CharType> static size_t allocationSize(unsigned length)
438 { 420 {
439 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof (StringImpl)) / sizeof(CharType))); 421 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof (StringImpl)) / sizeof(CharType)));
440 return sizeof(StringImpl) + length * sizeof(CharType); 422 return sizeof(StringImpl) + length * sizeof(CharType);
441 } 423 }
442 424
443 // This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings.
abarth-chromium 2014/03/24 16:46:54 I take it this comment is no longer accurate? It
444 static const unsigned s_copyCharsInlineCutOff = 20;
445
446 template <class UCharPredicate> PassRefPtr<StringImpl> stripMatchedCharacter s(UCharPredicate); 425 template <class UCharPredicate> PassRefPtr<StringImpl> stripMatchedCharacter s(UCharPredicate);
447 template <typename CharType, class UCharPredicate> PassRefPtr<StringImpl> si mplifyMatchedCharactersToSpace(UCharPredicate, StripBehavior); 426 template <typename CharType, class UCharPredicate> PassRefPtr<StringImpl> si mplifyMatchedCharactersToSpace(UCharPredicate, StripBehavior);
448 NEVER_INLINE unsigned hashSlowCase() const; 427 NEVER_INLINE unsigned hashSlowCase() const;
449 428
450 #ifdef STRING_STATS 429 #ifdef STRING_STATS
451 static StringStats m_stringStats; 430 static StringStats m_stringStats;
452 #endif 431 #endif
453 432
454 static unsigned m_highestStaticStringLength; 433 static unsigned m_highestStaticStringLength;
455 434
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 } 736 }
758 737
759 using WTF::StringImpl; 738 using WTF::StringImpl;
760 using WTF::equal; 739 using WTF::equal;
761 using WTF::equalNonNull; 740 using WTF::equalNonNull;
762 using WTF::TextCaseSensitivity; 741 using WTF::TextCaseSensitivity;
763 using WTF::TextCaseSensitive; 742 using WTF::TextCaseSensitive;
764 using WTF::TextCaseInsensitive; 743 using WTF::TextCaseInsensitive;
765 744
766 #endif 745 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698