Changeset 93835 in webkit for trunk/Source/JavaScriptCore/runtime/JSString.h
- Timestamp:
- Aug 25, 2011, 4:30:14 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/JSString.h
r93378 r93835 191 191 , m_fiberCount(0) 192 192 { 193 ASSERT(!m_value.isNull());194 Heap::heap(this)->reportExtraMemoryCost(value.impl()->cost());195 193 } 196 194 … … 202 200 , m_fiberCount(0) 203 201 { 204 ASSERT(!m_value.isNull());205 Heap::heap(this)->reportExtraMemoryCost(value.impl()->cost());206 202 } 207 203 JSString(JSGlobalData& globalData, PassRefPtr<StringImpl> value, HasOtherOwnerType) … … 211 207 , m_fiberCount(0) 212 208 { 213 ASSERT(!m_value.isNull());214 209 } 215 210 JSString(JSGlobalData& globalData, PassRefPtr<RopeImpl> rope) … … 218 213 , m_fiberCount(1) 219 214 { 220 m_fibers[0] = rope.leakRef();221 215 } 222 216 // This constructor constructs a new string by concatenating s1 & s2. … … 227 221 , m_fiberCount(fiberCount) 228 222 { 229 ASSERT(fiberCount <= s_maxInternalRopeLength);230 unsigned index = 0;231 appendStringInConstruct(index, s1);232 appendStringInConstruct(index, s2);233 ASSERT(fiberCount == index);234 223 } 235 224 // This constructor constructs a new string by concatenating s1 & s2. … … 240 229 , m_fiberCount(fiberCount) 241 230 { 242 ASSERT(fiberCount <= s_maxInternalRopeLength);243 unsigned index = 0;244 appendStringInConstruct(index, s1);245 appendStringInConstruct(index, u2);246 ASSERT(fiberCount == index);247 231 } 248 232 // This constructor constructs a new string by concatenating s1 & s2. … … 253 237 , m_fiberCount(fiberCount) 254 238 { 239 } 240 JSString(ExecState* exec) 241 : JSCell(exec->globalData(), exec->globalData().stringStructure.get()) 242 , m_length(0) 243 , m_fiberCount(s_maxInternalRopeLength) 244 { 245 } 246 247 // This constructor constructs a new string by concatenating u1 & u2. 248 JSString(JSGlobalData& globalData, const UString& u1, const UString& u2) 249 : JSCell(globalData, globalData.stringStructure.get()) 250 , m_length(u1.length() + u2.length()) 251 , m_fiberCount(2) 252 { 253 } 254 255 // This constructor constructs a new string by concatenating u1, u2 & u3. 256 JSString(JSGlobalData& globalData, const UString& u1, const UString& u2, const UString& u3) 257 : JSCell(globalData, globalData.stringStructure.get()) 258 , m_length(u1.length() + u2.length() + u3.length()) 259 , m_fiberCount(s_maxInternalRopeLength) 260 { 261 } 262 263 void finishCreation(JSGlobalData& globalData, const UString& value) 264 { 265 Base::finishCreation(globalData); 266 ASSERT(!m_value.isNull()); 267 Heap::heap(this)->reportExtraMemoryCost(value.impl()->cost()); 268 } 269 270 void finishCreation(JSGlobalData& globalData) 271 { 272 Base::finishCreation(globalData); 273 ASSERT(!m_value.isNull()); 274 } 275 276 void finishCreation(JSGlobalData& globalData, PassRefPtr<RopeImpl> rope) 277 { 278 Base::finishCreation(globalData); 279 m_fibers[0] = rope.leakRef(); 280 } 281 282 void finishCreation(JSGlobalData& globalData, unsigned fiberCount, JSString* s1, JSString* s2) 283 { 284 Base::finishCreation(globalData); 255 285 ASSERT(fiberCount <= s_maxInternalRopeLength); 256 286 unsigned index = 0; 257 appendStringInC onstruct(index, u1);258 appendStringInC onstruct(index, s2);287 appendStringInCreate(index, s1); 288 appendStringInCreate(index, s2); 259 289 ASSERT(fiberCount == index); 260 290 } 261 // This constructor constructs a new string by concatenating v1, v2 & v3. 291 292 void finishCreation(JSGlobalData& globalData, unsigned fiberCount, JSString* s1, const UString& u2) 293 { 294 Base::finishCreation(globalData); 295 ASSERT(fiberCount <= s_maxInternalRopeLength); 296 unsigned index = 0; 297 appendStringInCreate(index, s1); 298 appendStringInCreate(index, u2); 299 ASSERT(fiberCount == index); 300 } 301 302 void finishCreation(JSGlobalData& globalData, unsigned fiberCount, const UString& u1, JSString* s2) 303 { 304 Base::finishCreation(globalData); 305 ASSERT(fiberCount <= s_maxInternalRopeLength); 306 unsigned index = 0; 307 appendStringInCreate(index, u1); 308 appendStringInCreate(index, s2); 309 ASSERT(fiberCount == index); 310 } 311 312 // Fills in the new string by concatenating v1, v2 & v3. 262 313 // This should only be called with fiberCount <= 3 ... which since every 263 314 // value must require a fiberCount of at least one implies that the length 264 315 // for each value must be exactly 1! 265 JSString(ExecState* exec, JSValue v1, JSValue v2, JSValue v3) 266 : JSCell(exec->globalData(), exec->globalData().stringStructure.get()) 267 , m_length(0) 268 , m_fiberCount(s_maxInternalRopeLength) 269 { 270 constructorBody(exec, v1, v2, v3); 271 } 272 273 // This constructor constructs a new string by concatenating u1 & u2. 274 JSString(JSGlobalData& globalData, const UString& u1, const UString& u2) 275 : JSCell(globalData, globalData.stringStructure.get()) 276 , m_length(u1.length() + u2.length()) 277 , m_fiberCount(2) 278 { 316 void finishCreation(ExecState* exec, JSValue v1, JSValue v2, JSValue v3) 317 { 318 Base::finishCreation(exec->globalData()); 279 319 unsigned index = 0; 280 appendStringInConstruct(index, u1); 281 appendStringInConstruct(index, u2); 320 appendValueInCreateAndIncrementLength(exec, index, v1); 321 appendValueInCreateAndIncrementLength(exec, index, v2); 322 appendValueInCreateAndIncrementLength(exec, index, v3); 323 ASSERT(index == s_maxInternalRopeLength); 324 } 325 326 void finishCreation(JSGlobalData& globalData, const UString& u1, const UString& u2) 327 { 328 Base::finishCreation(globalData); 329 unsigned index = 0; 330 appendStringInCreate(index, u1); 331 appendStringInCreate(index, u2); 282 332 ASSERT(index <= s_maxInternalRopeLength); 283 333 } 284 334 285 // This constructor constructs a new string by concatenating u1, u2 & u3. 286 JSString(JSGlobalData& globalData, const UString& u1, const UString& u2, const UString& u3) 287 : JSCell(globalData, globalData.stringStructure.get()) 288 , m_length(u1.length() + u2.length() + u3.length()) 289 , m_fiberCount(s_maxInternalRopeLength) 290 { 335 void finishCreation(JSGlobalData& globalData, const UString& u1, const UString& u2, const UString& u3) 336 { 337 Base::finishCreation(globalData); 291 338 unsigned index = 0; 292 appendStringInC onstruct(index, u1);293 appendStringInC onstruct(index, u2);294 appendStringInC onstruct(index, u3);339 appendStringInCreate(index, u1); 340 appendStringInCreate(index, u2); 341 appendStringInCreate(index, u3); 295 342 ASSERT(index <= s_maxInternalRopeLength); 296 }297 298 protected:299 void constructorBody(ExecState* exec, JSValue v1, JSValue v2, JSValue v3)300 {301 unsigned index = 0;302 appendValueInConstructAndIncrementLength(exec, index, v1);303 appendValueInConstructAndIncrementLength(exec, index, v2);304 appendValueInConstructAndIncrementLength(exec, index, v3);305 ASSERT(index == s_maxInternalRopeLength);306 343 } 307 344 … … 309 346 static JSString* create(JSGlobalData& globalData, const UString& value) 310 347 { 311 return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, value); 348 JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, value); 349 newString->finishCreation(globalData, value); 350 return newString; 312 351 } 313 352 static JSString* createHasOtherOwner(JSGlobalData& globalData, const UString& value) 314 353 { 315 return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, value, HasOtherOwner); 354 JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, value, HasOtherOwner); 355 newString->finishCreation(globalData, value); 356 return newString; 316 357 } 317 358 static JSString* createHasOtherOwner(JSGlobalData& globalData, PassRefPtr<StringImpl> value) 318 359 { 319 return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, value, HasOtherOwner); 360 JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, value, HasOtherOwner); 361 newString->finishCreation(globalData); 362 return newString; 320 363 } 321 364 static JSString* create(JSGlobalData& globalData, PassRefPtr<RopeImpl> rope) 322 365 { 323 return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, rope); 366 RefPtr<RopeImpl> tempRope = rope; 367 JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, tempRope); 368 newString->finishCreation(globalData, tempRope); 369 return newString; 324 370 } 325 371 static JSString* create(JSGlobalData& globalData, unsigned fiberCount, JSString* s1, JSString* s2) 326 372 { 327 return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, fiberCount, s1, s2); 373 JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, fiberCount, s1, s2); 374 newString->finishCreation(globalData, fiberCount, s1, s2); 375 return newString; 328 376 } 329 377 static JSString* create(JSGlobalData& globalData, unsigned fiberCount, JSString* s1, const UString& u2) 330 378 { 331 return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, fiberCount, s1, u2); 379 JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, fiberCount, s1, u2); 380 newString->finishCreation(globalData, fiberCount, s1, u2); 381 return newString; 332 382 } 333 383 static JSString* create(JSGlobalData& globalData, unsigned fiberCount, const UString& u1, JSString* s2) 334 384 { 335 return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, fiberCount, u1, s2); 385 JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, fiberCount, u1, s2); 386 newString->finishCreation(globalData, fiberCount, u1, s2); 387 return newString; 336 388 } 337 389 static JSString* create(ExecState* exec, JSValue v1, JSValue v2, JSValue v3) 338 390 { 339 return new (allocateCell<JSString>(*exec->heap())) JSString(exec, v1, v2, v3); 391 JSString* newString = new (allocateCell<JSString>(*exec->heap())) JSString(exec); 392 newString->finishCreation(exec, v1, v2, v3); 393 return newString; 340 394 } 341 395 static JSString* create(JSGlobalData& globalData, const UString& u1, const UString& u2) 342 396 { 343 return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, u1, u2); 397 JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, u1, u2); 398 newString->finishCreation(globalData, u1, u2); 399 return newString; 344 400 } 345 401 static JSString* create(JSGlobalData& globalData, const UString& u1, const UString& u2, const UString& u3) 346 402 { 347 return new (allocateCell<JSString>(globalData.heap)) JSString(globalData, u1, u2, u3); 403 JSString* newString = new (allocateCell<JSString>(globalData.heap)) JSString(globalData, u1, u2, u3); 404 newString->finishCreation(globalData, u1, u2, u3); 405 return newString; 348 406 } 349 407 … … 398 456 JSString* substringFromRope(ExecState*, unsigned offset, unsigned length); 399 457 400 void appendStringInC onstruct(unsigned& index, const UString& string)458 void appendStringInCreate(unsigned& index, const UString& string) 401 459 { 402 460 StringImpl* impl = string.impl(); … … 406 464 } 407 465 408 void appendStringInC onstruct(unsigned& index, JSString* jsString)466 void appendStringInCreate(unsigned& index, JSString* jsString) 409 467 { 410 468 if (jsString->isRope()) { … … 415 473 } 416 474 } else 417 appendStringInC onstruct(index, jsString->string());418 } 419 420 void appendValueInC onstructAndIncrementLength(ExecState* exec, unsigned& index, JSValue v)475 appendStringInCreate(index, jsString->string()); 476 } 477 478 void appendValueInCreateAndIncrementLength(ExecState* exec, unsigned& index, JSValue v) 421 479 { 422 480 if (v.isString()) { … … 424 482 JSString* s = static_cast<JSString*>(v.asCell()); 425 483 ASSERT(s->fiberCount() == 1); 426 appendStringInC onstruct(index, s);484 appendStringInCreate(index, s); 427 485 m_length += s->length(); 428 486 } else {
Note:
See TracChangeset
for help on using the changeset viewer.