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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 bool threadSafeMatch(const String&, const QualifiedName&); | 108 bool threadSafeMatch(const String&, const QualifiedName&); |
109 | 109 |
110 StringImpl* findStringIfStatic(const UChar* characters, unsigned length); | 110 StringImpl* findStringIfStatic(const UChar* characters, unsigned length); |
111 | 111 |
112 enum CharacterWidth { | 112 enum CharacterWidth { |
113 Likely8Bit, | 113 Likely8Bit, |
114 Force8Bit, | 114 Force8Bit, |
115 Force16Bit | 115 Force16Bit |
116 }; | 116 }; |
117 | 117 |
| 118 inline static String attemptStaticStringCreation(const UChar* characters, size_t
size, CharacterWidth width) |
| 119 { |
| 120 String string(findStringIfStatic(characters, size)); |
| 121 if (string.impl()) |
| 122 return string; |
| 123 if (width == Likely8Bit) |
| 124 string = StringImpl::create8BitIfPossible(characters, size); |
| 125 else if (width == Force8Bit) |
| 126 string = String::make8BitFrom16BitSource(characters, size); |
| 127 else |
| 128 string = String(characters, size); |
| 129 |
| 130 return string; |
| 131 } |
| 132 |
118 template<size_t inlineCapacity> | 133 template<size_t inlineCapacity> |
119 static String attemptStaticStringCreation(const Vector<UChar, inlineCapacity>& v
ector, CharacterWidth width) | 134 static String attemptStaticStringCreation(const Vector<UChar, inlineCapacity>& v
ector, CharacterWidth width) |
120 { | 135 { |
121 String string(findStringIfStatic(vector.data(), vector.size())); | 136 return attemptStaticStringCreation(vector.data(), vector.size(), width); |
122 if (string.impl()) | 137 } |
123 return string; | |
124 if (width == Likely8Bit) | |
125 string = StringImpl::create8BitIfPossible(vector); | |
126 else if (width == Force8Bit) | |
127 string = String::make8BitFrom16BitSource(vector); | |
128 else | |
129 string = String(vector); | |
130 | 138 |
131 return string; | 139 inline static String attemptStaticStringCreation(const String str, CharacterWidt
h width) |
| 140 { |
| 141 ASSERT(!str.is8Bit()); |
| 142 return attemptStaticStringCreation(str.characters16(), str.length(), width); |
132 } | 143 } |
133 | 144 |
| 145 |
134 } | 146 } |
135 #endif | 147 #endif |
OLD | NEW |