| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "wtf/text/StringStatics.h" | 26 #include "wtf/text/StringStatics.h" |
| 27 | 27 |
| 28 #include "wtf/DynamicAnnotations.h" | 28 #include "wtf/DynamicAnnotations.h" |
| 29 #include "wtf/MainThread.h" | 29 #include "wtf/MainThread.h" |
| 30 #include "wtf/StaticConstructors.h" | 30 #include "wtf/StaticConstructors.h" |
| 31 #include "wtf/text/AtomicString.h" | 31 #include "wtf/text/AtomicString.h" |
| 32 #include "wtf/text/StringImpl.h" | 32 #include "wtf/text/StringImpl.h" |
| 33 | 33 |
| 34 namespace WTF { | 34 namespace WTF { |
| 35 | 35 |
| 36 StringImpl* StringImpl::empty() | 36 StringImpl* StringImpl::empty() { |
| 37 { | 37 DEFINE_STATIC_LOCAL(StringImpl, emptyString, (ConstructEmptyString)); |
| 38 DEFINE_STATIC_LOCAL(StringImpl, emptyString, (ConstructEmptyString)); | 38 WTF_ANNOTATE_BENIGN_RACE(&emptyString, |
| 39 WTF_ANNOTATE_BENIGN_RACE(&emptyString, | 39 "Benign race on the reference counter of a static " |
| 40 "Benign race on the reference counter of a static string created by Stri
ngImpl::empty"); | 40 "string created by StringImpl::empty"); |
| 41 return &emptyString; | 41 return &emptyString; |
| 42 } | 42 } |
| 43 | 43 |
| 44 StringImpl* StringImpl::empty16Bit() | 44 StringImpl* StringImpl::empty16Bit() { |
| 45 { | 45 DEFINE_STATIC_LOCAL(StringImpl, emptyString, (ConstructEmptyString16Bit)); |
| 46 DEFINE_STATIC_LOCAL(StringImpl, emptyString, (ConstructEmptyString16Bit)); | 46 WTF_ANNOTATE_BENIGN_RACE(&emptyString, |
| 47 WTF_ANNOTATE_BENIGN_RACE(&emptyString, | 47 "Benign race on the reference counter of a static " |
| 48 "Benign race on the reference counter of a static string created by Stri
ngImpl::empty16Bit"); | 48 "string created by StringImpl::empty16Bit"); |
| 49 return &emptyString; | 49 return &emptyString; |
| 50 } | 50 } |
| 51 | 51 |
| 52 WTF_EXPORT DEFINE_GLOBAL(AtomicString, nullAtom) | 52 WTF_EXPORT DEFINE_GLOBAL(AtomicString, nullAtom) WTF_EXPORT |
| 53 WTF_EXPORT DEFINE_GLOBAL(AtomicString, emptyAtom) | 53 DEFINE_GLOBAL(AtomicString, emptyAtom) WTF_EXPORT |
| 54 WTF_EXPORT DEFINE_GLOBAL(AtomicString, starAtom) | 54 DEFINE_GLOBAL(AtomicString, starAtom) WTF_EXPORT |
| 55 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xmlAtom) | 55 DEFINE_GLOBAL(AtomicString, xmlAtom) WTF_EXPORT |
| 56 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xmlnsAtom) | 56 DEFINE_GLOBAL(AtomicString, xmlnsAtom) WTF_EXPORT |
| 57 WTF_EXPORT DEFINE_GLOBAL(AtomicString, xlinkAtom) | 57 DEFINE_GLOBAL(AtomicString, xlinkAtom) |
| 58 | 58 |
| 59 // This is not an AtomicString because it is unlikely to be used as an | 59 // This is not an AtomicString because it is unlikely to be used as an |
| 60 // event/element/attribute name, so it shouldn't pollute the AtomicString hash | 60 // event/element/attribute name, so it shouldn't pollute the AtomicString ha
sh |
| 61 // table. | 61 // table. |
| 62 WTF_EXPORT DEFINE_GLOBAL(String, xmlnsWithColon) | 62 WTF_EXPORT DEFINE_GLOBAL(String, xmlnsWithColon) |
| 63 | 63 |
| 64 NEVER_INLINE unsigned StringImpl::hashSlowCase() const | 64 NEVER_INLINE unsigned StringImpl::hashSlowCase() const { |
| 65 { | 65 if (is8Bit()) |
| 66 if (is8Bit()) | 66 setHash(StringHasher::computeHashAndMaskTop8Bits(characters8(), m_length)); |
| 67 setHash(StringHasher::computeHashAndMaskTop8Bits(characters8(), m_length
)); | 67 else |
| 68 else | 68 setHash(StringHasher::computeHashAndMaskTop8Bits(characters16(), m_length)); |
| 69 setHash(StringHasher::computeHashAndMaskTop8Bits(characters16(), m_lengt
h)); | 69 return existingHash(); |
| 70 return existingHash(); | |
| 71 } | 70 } |
| 72 | 71 |
| 73 void AtomicString::init() | 72 void AtomicString::init() { |
| 74 { | 73 ASSERT(isMainThread()); |
| 75 ASSERT(isMainThread()); | |
| 76 | 74 |
| 77 new (NotNull, (void*)&nullAtom) AtomicString; | 75 new (NotNull, (void*)&nullAtom) AtomicString; |
| 78 new (NotNull, (void*)&emptyAtom) AtomicString(""); | 76 new (NotNull, (void*)&emptyAtom) AtomicString(""); |
| 79 } | 77 } |
| 80 | 78 |
| 81 template<unsigned charactersCount> | 79 template <unsigned charactersCount> |
| 82 PassRefPtr<StringImpl> addStaticASCIILiteral(const char (&characters)[characters
Count]) | 80 PassRefPtr<StringImpl> addStaticASCIILiteral( |
| 83 { | 81 const char (&characters)[charactersCount]) { |
| 84 unsigned length = charactersCount - 1; | 82 unsigned length = charactersCount - 1; |
| 85 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(reinterpret_cast<co
nst LChar*>(characters), length); | 83 unsigned hash = StringHasher::computeHashAndMaskTop8Bits( |
| 86 return adoptRef(StringImpl::createStatic(characters, length, hash)); | 84 reinterpret_cast<const LChar*>(characters), length); |
| 85 return adoptRef(StringImpl::createStatic(characters, length, hash)); |
| 87 } | 86 } |
| 88 | 87 |
| 89 void StringStatics::init() | 88 void StringStatics::init() { |
| 90 { | 89 ASSERT(isMainThread()); |
| 91 ASSERT(isMainThread()); | |
| 92 | 90 |
| 93 // FIXME: These should be allocated at compile time. | 91 // FIXME: These should be allocated at compile time. |
| 94 new (NotNull, (void*)&starAtom) AtomicString("*", AtomicString::ConstructFro
mLiteral); | 92 new (NotNull, (void*)&starAtom) |
| 95 new (NotNull, (void*)&xmlAtom) AtomicString(addStaticASCIILiteral("xml")); | 93 AtomicString("*", AtomicString::ConstructFromLiteral); |
| 96 new (NotNull, (void*)&xmlnsAtom) AtomicString(addStaticASCIILiteral("xmlns")
); | 94 new (NotNull, (void*)&xmlAtom) AtomicString(addStaticASCIILiteral("xml")); |
| 97 new (NotNull, (void*)&xlinkAtom) AtomicString(addStaticASCIILiteral("xlink")
); | 95 new (NotNull, (void*)&xmlnsAtom) AtomicString(addStaticASCIILiteral("xmlns")); |
| 98 new (NotNull, (void*)&xmlnsWithColon) String("xmlns:"); | 96 new (NotNull, (void*)&xlinkAtom) AtomicString(addStaticASCIILiteral("xlink")); |
| 97 new (NotNull, (void*)&xmlnsWithColon) String("xmlns:"); |
| 99 } | 98 } |
| 100 | |
| 101 } | 99 } |
| OLD | NEW |