| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 | 73 |
| 74 void AtomicString::init() | 74 void AtomicString::init() |
| 75 { | 75 { |
| 76 ASSERT(isMainThread()); | 76 ASSERT(isMainThread()); |
| 77 | 77 |
| 78 new (NotNull, (void*)&nullAtom) AtomicString; | 78 new (NotNull, (void*)&nullAtom) AtomicString; |
| 79 new (NotNull, (void*)&emptyAtom) AtomicString(""); | 79 new (NotNull, (void*)&emptyAtom) AtomicString(""); |
| 80 } | 80 } |
| 81 | 81 |
| 82 template <unsigned charactersCount> |
| 83 struct PreallocatedStringImplStorage { |
| 84 // A StringImpl is built at stringImplStorage in-place. |
| 85 // |characters| must be placed soon after |stringImplStorage| to match the m
emory layout requirement of StringImpl. |
| 86 char stringImplStorage[sizeof(StringImpl)]; |
| 87 char characters[charactersCount]; |
| 88 }; |
| 89 |
| 82 template<unsigned charactersCount> | 90 template<unsigned charactersCount> |
| 83 PassRefPtr<StringImpl> addStaticASCIILiteral(const char (&characters)[characters
Count]) | 91 PassRefPtr<StringImpl> addStaticASCIILiteral(PreallocatedStringImplStorage<chara
ctersCount>& storage) |
| 84 { | 92 { |
| 93 ASSERT(reinterpret_cast<char*>(reinterpret_cast<StringImpl*>(&storage) + 1)
== storage.characters); |
| 85 unsigned length = charactersCount - 1; | 94 unsigned length = charactersCount - 1; |
| 86 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(reinterpret_cast<co
nst LChar*>(characters), length); | 95 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(reinterpret_cast<co
nst LChar*>(storage.characters), length); |
| 87 return adoptRef(StringImpl::createStatic(characters, length, hash)); | 96 return adoptRef(StringImpl::createPreallocatedStatic(&storage, length, hash)
); |
| 88 } | 97 } |
| 89 | 98 |
| 90 void StringStatics::init() | 99 void StringStatics::init() |
| 91 { | 100 { |
| 92 ASSERT(isMainThread()); | 101 ASSERT(isMainThread()); |
| 93 | 102 |
| 103 #define ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL(name, literal) \ |
| 104 static PreallocatedStringImplStorage<sizeof(literal)> name = {{}, literal} |
| 105 |
| 106 ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL(star, "*"); |
| 107 ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL(xml, "xml"); |
| 108 ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL(xmlns, "xmlns"); |
| 109 ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL(xlink, "xlink"); |
| 110 ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL(xmlnsWithColon, "xmlns:"); |
| 111 |
| 112 #undef ALLOCATE_STRING_IMPL_STORAGE_FOR_LITERAL |
| 113 |
| 94 // FIXME: These should be allocated at compile time. | 114 // FIXME: These should be allocated at compile time. |
| 95 new (NotNull, (void*)&starAtom) AtomicString("*", AtomicString::ConstructFro
mLiteral); | 115 new (NotNull, (void*)&starAtom) AtomicString(addStaticASCIILiteral(star)); |
| 96 new (NotNull, (void*)&xmlAtom) AtomicString(addStaticASCIILiteral("xml")); | 116 new (NotNull, (void*)&xmlAtom) AtomicString(addStaticASCIILiteral(xml)); |
| 97 new (NotNull, (void*)&xmlnsAtom) AtomicString(addStaticASCIILiteral("xmlns")
); | 117 new (NotNull, (void*)&xmlnsAtom) AtomicString(addStaticASCIILiteral(xmlns)); |
| 98 new (NotNull, (void*)&xlinkAtom) AtomicString(addStaticASCIILiteral("xlink")
); | 118 new (NotNull, (void*)&xlinkAtom) AtomicString(addStaticASCIILiteral(xlink)); |
| 99 new (NotNull, (void*)&xmlnsWithColon) String("xmlns:"); | 119 new (NotNull, (void*)&xlinkAtom) AtomicString(addStaticASCIILiteral(xmlnsWit
hColon)); |
| 100 } | 120 } |
| 101 | 121 |
| 102 } | 122 } |
| OLD | NEW |