Changeset 100202 in webkit
- Timestamp:
- Nov 14, 2011, 3:51:06 PM (14 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r100200 r100202 1 2011-11-14 Michael Saboff <msaboff@apple.com> 2 3 Towards 8 bit strings - Add 8 bit handling to JSString Ropes 4 https://bugs.webkit.org/show_bug.cgi?id=72317 5 6 Added bit to track that a rope is made up of all 8 bit fibers. 7 Created an 8 bit path (fast and slow cases) to handle 8 bit 8 only ropes. 9 10 Reviewed by Oliver Hunt. 11 12 * runtime/JSString.cpp: 13 (JSC::JSString::resolveRope): 14 (JSC::JSString::resolveRopeSlowCase8): 15 (JSC::JSString::resolveRopeSlowCase16): 16 * runtime/JSString.h: 17 (JSC::RopeBuilder::finishCreation): 18 (JSC::RopeBuilder::is8Bit): 19 (JSC::jsSubstring8): 20 1 21 2011-11-14 Geoffrey Garen <ggaren@apple.com> 2 22 -
trunk/Source/JavaScriptCore/runtime/JSString.cpp
r100006 r100202 63 63 ASSERT(isRope()); 64 64 65 if (is8Bit()) { 66 LChar* buffer; 67 if (PassRefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) 68 m_value = newImpl; 69 else { 70 outOfMemory(exec); 71 return; 72 } 73 74 for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { 75 if (m_fibers[i]->isRope()) 76 return resolveRopeSlowCase(exec, buffer); 77 } 78 79 LChar* position = buffer; 80 for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) { 81 StringImpl* string = m_fibers[i]->m_value.impl(); 82 unsigned length = string->length(); 83 StringImpl::copyChars(position, string->characters8(), length); 84 position += length; 85 m_fibers[i].clear(); 86 } 87 ASSERT((buffer + m_length) == position); 88 ASSERT(!isRope()); 89 90 return; 91 } 92 65 93 UChar* buffer; 66 94 if (PassRefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) … … 80 108 StringImpl* string = m_fibers[i]->m_value.impl(); 81 109 unsigned length = string->length(); 82 StringImpl::copyChars(position, string->characters 16(), length);110 StringImpl::copyChars(position, string->characters(), length); 83 111 position += length; 84 112 m_fibers[i].clear(); … … 88 116 } 89 117 90 // Overview: this methods convertsa JSString from holding a string in rope form118 // Overview: These functions convert a JSString from holding a string in rope form 91 119 // down to a simple UString representation. It does so by building up the string 92 120 // backwards, since we want to avoid recursion, we expect that the tree structure … … 98 126 // only fill the queue with the number of substrings at any given level in a 99 127 // rope-of-ropes.) 100 void JSString::resolveRopeSlowCase(ExecState* exec, UChar* buffer) const128 void JSString::resolveRopeSlowCase(ExecState* exec, LChar* buffer) const 101 129 { 102 130 UNUSED_PARAM(exec); 103 131 104 UChar* position = buffer + m_length; // We will be working backwards over the rope.132 LChar* position = buffer + m_length; // We will be working backwards over the rope. 105 133 Vector<JSString*, 32> workQueue; // Putting strings into a Vector is only OK because there are no GC points in this method. 106 134 … … 124 152 unsigned length = string->length(); 125 153 position -= length; 126 StringImpl::copyChars(position, string->characters16(), length); 154 StringImpl::copyChars(position, string->characters8(), length); 155 } 156 157 ASSERT(buffer == position); 158 ASSERT(!isRope()); 159 } 160 161 void JSString::resolveRopeSlowCase(ExecState* exec, UChar* buffer) const 162 { 163 UNUSED_PARAM(exec); 164 165 UChar* position = buffer + m_length; // We will be working backwards over the rope. 166 Vector<JSString*, 32> workQueue; // These strings are kept alive by the parent rope, so using a Vector is OK. 167 168 for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) 169 workQueue.append(m_fibers[i].get()); 170 171 while (!workQueue.isEmpty()) { 172 JSString* currentFiber = workQueue.last(); 173 workQueue.removeLast(); 174 175 if (currentFiber->isRope()) { 176 for (size_t i = 0; i < s_maxInternalRopeLength && currentFiber->m_fibers[i]; ++i) 177 workQueue.append(currentFiber->m_fibers[i].get()); 178 continue; 179 } 180 181 StringImpl* string = static_cast<StringImpl*>(currentFiber->m_value.impl()); 182 unsigned length = string->length(); 183 position -= length; 184 StringImpl::copyChars(position, string->characters(), length); 127 185 } 128 186 -
trunk/Source/JavaScriptCore/runtime/JSString.h
r99754 r100202 23 23 #ifndef JSString_h 24 24 #define JSString_h 25 26 25 #include "CallFrame.h" 27 26 #include "CommonIdentifiers.h" … … 86 85 m_jsString->m_fibers[m_index++].set(m_globalData, m_jsString, jsString); 87 86 m_jsString->m_length += jsString->m_length; 87 m_jsString->m_is8Bit = m_jsString->m_is8Bit && jsString->m_is8Bit; 88 88 } 89 89 … … 128 128 Base::finishCreation(globalData); 129 129 m_length = length; 130 m_is8Bit = m_value.impl()->is8Bit(); 130 131 } 131 132 … … 135 136 Base::finishCreation(globalData); 136 137 m_length = length; 138 m_is8Bit = m_value.impl()->is8Bit(); 137 139 Heap::heap(this)->reportExtraMemoryCost(cost); 138 140 } … … 142 144 Base::finishCreation(globalData); 143 145 m_length = s1->length() + s2->length(); 146 m_is8Bit = (s1->is8Bit() && s2->is8Bit()); 144 147 m_fibers[0].set(globalData, this, s1); 145 148 m_fibers[1].set(globalData, this, s2); … … 150 153 Base::finishCreation(globalData); 151 154 m_length = s1->length() + s2->length() + s3->length(); 155 m_is8Bit = (s1->is8Bit() && s2->is8Bit() && s3->is8Bit()); 152 156 m_fibers[0].set(globalData, this, s1); 153 157 m_fibers[1].set(globalData, this, s2); … … 245 249 246 250 void resolveRope(ExecState*) const; 251 void resolveRopeSlowCase(ExecState*, LChar*) const; 247 252 void resolveRopeSlowCase(ExecState*, UChar*) const; 248 253 void outOfMemory(ExecState*) const; … … 257 262 258 263 // A string is represented either by a UString or a rope of fibers. 264 bool m_is8Bit : 1; 259 265 unsigned m_length; 260 266 mutable UString m_value; … … 262 268 263 269 bool isRope() const { return m_value.isNull(); } 270 bool is8Bit() const { return m_is8Bit; } 264 271 UString& string() { ASSERT(!isRope()); return m_value; } 265 272
Note:
See TracChangeset
for help on using the changeset viewer.