Chromium Code Reviews| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "StringStatics.h" | |
| 27 | 28 |
| 28 #ifdef SKIP_STATIC_CONSTRUCTORS_ON_GCC | 29 #ifdef SKIP_STATIC_CONSTRUCTORS_ON_GCC |
| 29 #define ATOMICSTRING_HIDE_GLOBALS 1 | 30 #define ATOMICSTRING_HIDE_GLOBALS 1 |
| 30 #endif | 31 #endif |
| 31 | 32 |
| 32 #include "AtomicString.h" | 33 #include "AtomicString.h" |
| 33 #include "DynamicAnnotations.h" | 34 #include "DynamicAnnotations.h" |
| 34 #include "MainThread.h" | 35 #include "MainThread.h" |
| 35 #include "StaticConstructors.h" | 36 #include "StaticConstructors.h" |
| 36 #include "StringImpl.h" | 37 #include "StringImpl.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 66 if (is8Bit()) | 67 if (is8Bit()) |
| 67 setHash(StringHasher::computeHashAndMaskTop8Bits(m_data8, m_length)); | 68 setHash(StringHasher::computeHashAndMaskTop8Bits(m_data8, m_length)); |
| 68 else | 69 else |
| 69 setHash(StringHasher::computeHashAndMaskTop8Bits(m_data16, m_length)); | 70 setHash(StringHasher::computeHashAndMaskTop8Bits(m_data16, m_length)); |
| 70 return existingHash(); | 71 return existingHash(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 void AtomicString::init() | 74 void AtomicString::init() |
| 74 { | 75 { |
| 75 static bool initialized; | 76 static bool initialized; |
| 76 if (!initialized) { | 77 if (initialized) |
| 77 // Initialization is not thread safe, so this function must be called fr om the main thread first. | 78 return; |
| 78 ASSERT(isMainThread()); | 79 initialized = true; |
| 79 | 80 |
| 80 // Use placement new to initialize the globals. | 81 ASSERT(isMainThread()); |
| 81 new (NotNull, (void*)&nullAtom) AtomicString; | |
| 82 new (NotNull, (void*)&emptyAtom) AtomicString(""); | |
| 83 new (NotNull, (void*)&textAtom) AtomicString("#text", AtomicString::Cons tructFromLiteral); | |
| 84 new (NotNull, (void*)&commentAtom) AtomicString("#comment", AtomicString ::ConstructFromLiteral); | |
| 85 new (NotNull, (void*)&starAtom) AtomicString("*", AtomicString::Construc tFromLiteral); | |
| 86 new (NotNull, (void*)&xmlAtom) AtomicString("xml", AtomicString::Constru ctFromLiteral); | |
| 87 new (NotNull, (void*)&xmlnsAtom) AtomicString("xmlns", AtomicString::Con structFromLiteral); | |
| 88 new (NotNull, (void*)&xlinkAtom) AtomicString("xlink", AtomicString::Con structFromLiteral); | |
| 89 | 82 |
| 90 initialized = true; | 83 new (NotNull, (void*)&nullAtom) AtomicString; |
| 91 } | 84 new (NotNull, (void*)&emptyAtom) AtomicString(""); |
|
eseidel
2013/04/10 20:53:50
I assume this is going to correctly end up with "e
abarth-chromium
2013/04/10 21:00:51
Yes. This part isn't changing. I'm just switchin
| |
| 85 } | |
| 86 | |
| 87 void StringStatics::init() | |
| 88 { | |
| 89 static bool initialized; | |
| 90 if (initialized) | |
| 91 return; | |
| 92 initialized = true; | |
| 93 | |
| 94 ASSERT(isMainThread()); | |
| 95 | |
| 96 // FIXME: These should be allocated at compile time. | |
| 97 new (NotNull, (void*)&textAtom) AtomicString("#text", AtomicString::Construc tFromLiteral); | |
| 98 new (NotNull, (void*)&commentAtom) AtomicString("#comment", AtomicString::Co nstructFromLiteral); | |
| 99 new (NotNull, (void*)&starAtom) AtomicString("*", AtomicString::ConstructFro mLiteral); | |
| 100 new (NotNull, (void*)&xmlAtom) AtomicString("xml", AtomicString::ConstructFr omLiteral); | |
| 101 new (NotNull, (void*)&xmlnsAtom) AtomicString("xmlns", AtomicString::Constru ctFromLiteral); | |
| 102 new (NotNull, (void*)&xlinkAtom) AtomicString("xlink", AtomicString::Constru ctFromLiteral); | |
| 92 } | 103 } |
| 93 | 104 |
| 94 } | 105 } |
| OLD | NEW |