Changeset 59161 in webkit for trunk/JavaScriptCore/runtime/JSString.cpp
- Timestamp:
- May 11, 2010, 11:42:46 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSString.cpp
r57912 r59161 76 76 unsigned fiberCountMinusOne = rope->fiberCount() - 1; 77 77 for (unsigned i = 0; i < fiberCountMinusOne; ++i) 78 workQueue.append(rope->fibers( i));79 currentFiber = rope->fibers( fiberCountMinusOne);78 workQueue.append(rope->fibers()[i]); 79 currentFiber = rope->fibers()[fiberCountMinusOne]; 80 80 } else { 81 81 UStringImpl* string = static_cast<UStringImpl*>(currentFiber); … … 105 105 } 106 106 107 JSValue JSString::replaceCharacter(ExecState* exec, UChar character, const UString& replacement) 108 { 109 if (!isRope()) { 110 size_t matchPosition = m_value.find(character); 111 if (matchPosition == notFound) 112 return JSValue(this); 113 return jsString(exec, m_value.substr(0, matchPosition), replacement, m_value.substr(matchPosition + 1)); 114 } 115 116 RopeIterator end; 117 118 // Count total fibers and find matching string. 119 size_t fiberCount = 0; 120 UStringImpl* matchString = 0; 121 size_t matchPosition = notFound; 122 for (RopeIterator it(m_other.m_fibers, m_fiberCount); it != end; ++it) { 123 ++fiberCount; 124 if (matchString) 125 continue; 126 127 UStringImpl* string = *it; 128 matchPosition = string->find(character); 129 if (matchPosition == notFound) 130 continue; 131 matchString = string; 132 } 133 134 if (!matchString) 135 return this; 136 137 RopeBuilder builder(replacement.size() ? fiberCount + 2 : fiberCount + 1); 138 if (UNLIKELY(builder.isOutOfMemory())) 139 return throwOutOfMemoryError(exec); 140 141 for (RopeIterator it(m_other.m_fibers, m_fiberCount); it != end; ++it) { 142 UStringImpl* string = *it; 143 if (string != matchString) { 144 builder.append(UString(string)); 145 continue; 146 } 147 148 builder.append(UString(string).substr(0, matchPosition)); 149 if (replacement.size()) 150 builder.append(replacement); 151 builder.append(UString(string).substr(matchPosition + 1)); 152 } 153 154 JSGlobalData* globalData = &exec->globalData(); 155 return JSValue(new (globalData) JSString(globalData, builder.release())); 156 } 157 107 158 JSString* JSString::getIndexSlowCase(ExecState* exec, unsigned i) 108 159 {
Note:
See TracChangeset
for help on using the changeset viewer.