Changeset 34821 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp
- Timestamp:
- Jun 26, 2008, 7:53:42 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ustring.cpp
r34581 r34821 775 775 } 776 776 777 UString& UString::append(const UChar* tData, int tSize) 778 { 779 int thisSize = size(); 780 int thisOffset = m_rep->offset; 781 int length = thisSize + tSize; 782 783 // possible cases: 784 if (tSize == 0) { 785 // t is empty 786 } else if (thisSize == 0) { 787 // this is empty 788 m_rep = Rep::createCopying(tData, tSize); 789 } else if (m_rep->baseIsSelf() && m_rep->rc == 1) { 790 // this is direct and has refcount of 1 (so we can just alter it directly) 791 expandCapacity(thisOffset + length); 792 if (data()) { 793 memcpy(const_cast<UChar*>(data() + thisSize), tData, tSize * sizeof(UChar)); 794 m_rep->len = length; 795 m_rep->_hash = 0; 796 } 797 } else if (thisOffset + thisSize == usedCapacity() && thisSize >= minShareSize) { 798 // this reaches the end of the buffer - extend it if it's long enough to append to 799 expandCapacity(thisOffset + length); 800 if (data()) { 801 memcpy(const_cast<UChar*>(data() + thisSize), tData, tSize * sizeof(UChar)); 802 m_rep = Rep::create(m_rep, 0, length); 803 } 804 } else { 805 // this is shared with someone using more capacity, gotta make a whole new string 806 size_t newCapacity = expandedSize(length, 0); 807 UChar* d = allocChars(newCapacity); 808 if (!d) 809 m_rep = &Rep::null; 810 else { 811 memcpy(d, data(), thisSize * sizeof(UChar)); 812 memcpy(const_cast<UChar*>(d + thisSize), tData, tSize * sizeof(UChar)); 813 m_rep = Rep::create(d, length); 814 m_rep->capacity = newCapacity; 815 } 816 } 817 818 return *this; 819 } 820 777 821 UString& UString::append(const char *t) 778 822 {
Note:
See TracChangeset
for help on using the changeset viewer.