Changeset 51671 in webkit for trunk/JavaScriptCore/runtime/Operations.h
- Timestamp:
- Dec 3, 2009, 6:15:18 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/Operations.h
r50704 r51671 205 205 bool leftIsString = v1.isString(); 206 206 if (leftIsString && v2.isString()) { 207 if (asString(v1)->isRope() || asString(v2)->isRope()) { 208 RefPtr<JSString::Rope> rope = JSString::Rope::create(2); 209 rope->initializeFiber(0, asString(v1)); 210 rope->initializeFiber(1, asString(v2)); 211 JSGlobalData* globalData = &callFrame->globalData(); 212 return new (globalData) JSString(globalData, rope.release()); 213 } 214 207 215 RefPtr<UString::Rep> value = concatenate(asString(v1)->value().rep(), asString(v2)->value().rep()); 208 216 if (!value) … … 299 307 ASSERT(count >= 3); 300 308 301 // Estimate the amount of space required to hold the entire string. If all 302 // arguments are strings, we can easily calculate the exact amount of space 303 // required. For any other arguments, for now let's assume they may require 304 // 11 UChars of storage. This is enouch to hold any int, and likely is also 305 // reasonable for the other immediates. We may want to come back and tune 306 // this value at some point. 307 unsigned bufferSize = 0; 309 RefPtr<JSString::Rope> rope = JSString::Rope::create(count); 310 308 311 for (unsigned i = 0; i < count; ++i) { 309 312 JSValue v = strings[i].jsValue(); 310 313 if (LIKELY(v.isString())) 311 bufferSize += asString(v)->value().size();314 rope->initializeFiber(i, asString(v)); 312 315 else 313 bufferSize += 11; 314 } 315 316 // Allocate an output string to store the result. 317 // If the first argument is a String, and if it has the capacity (or can grow 318 // its capacity) to hold the entire result then use this as a base to concatenate 319 // onto. Otherwise, allocate a new empty output buffer. 320 JSValue firstValue = strings[0].jsValue(); 321 RefPtr<UString::Rep> resultRep; 322 if (firstValue.isString() && (resultRep = asString(firstValue)->value().rep())->reserveCapacity(bufferSize)) { 323 // We're going to concatenate onto the first string - remove it from the list of items to be appended. 324 ++strings; 325 --count; 326 } else 327 resultRep = UString::Rep::createEmptyBuffer(bufferSize); 328 UString result(resultRep); 329 330 // Loop over the operands, writing them into the output buffer. 331 for (unsigned i = 0; i < count; ++i) { 332 JSValue v = strings[i].jsValue(); 333 if (LIKELY(v.isString())) 334 result.append(asString(v)->value()); 335 else 336 result.append(v.toString(callFrame)); 337 } 338 339 return jsString(callFrame, result); 340 } 341 316 rope->initializeFiber(i, v.toString(callFrame).rep()); 317 } 318 319 JSGlobalData* globalData = &callFrame->globalData(); 320 return new (globalData) JSString(globalData, rope.release()); 321 } 342 322 } // namespace JSC 343 323
Note:
See TracChangeset
for help on using the changeset viewer.