Changeset 127366 in webkit
- Timestamp:
- Sep 1, 2012 1:20:01 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r127365 r127366 1 2012-09-01 Adam Barth <abarth@webkit.org> 2 3 Remove all-but-one use of WTF::String::operator+= from WebCore 4 https://bugs.webkit.org/show_bug.cgi?id=95508 5 6 Reviewed by Benjamin Poulain. 7 8 This patch removes all the uses of WTF::String::operator+= from 9 WebCore, except those in WorkerScriptLoader (which need a more delicate 10 patch). There were actually a handful of legitimate use cases for += in 11 this group. I've replaced them with calls to String::append rather than 12 += so that we can remove += and encourage most contributors to use 13 more efficient string idioms. 14 15 (There are likely some more uses in WebCore hiding in port-specific 16 code---this patch covers only those call sites found when compiling the 17 chromium-mac port.) 18 19 * inspector/InspectorStyleTextEditor.cpp: 20 (WebCore::InspectorStyleTextEditor::insertProperty): 21 - This complicated function looks really inefficient, but I didn't 22 have the heart to rewrite it. 23 * inspector/NetworkResourcesData.cpp: 24 (WebCore::NetworkResourcesData::ResourceData::decodeDataToContent): 25 * loader/cache/CachedCSSStyleSheet.cpp: 26 (WebCore::CachedCSSStyleSheet::sheetText): 27 (WebCore::CachedCSSStyleSheet::data): 28 * loader/cache/CachedFont.cpp: 29 (WebCore::CachedFont::ensureSVGFontData): 30 * loader/cache/CachedScript.cpp: 31 (WebCore::CachedScript::script): 32 * loader/cache/CachedXSLStyleSheet.cpp: 33 (WebCore::CachedXSLStyleSheet::data): 34 - This decoder/flush pattern can probably be improved by combining 35 the decode and flush operations, but I didn't do that in this 36 patch. 37 * page/FrameTree.cpp: 38 (WebCore::FrameTree::uniqueChildName): 39 - I found this code very amusing. It's worried enough about 40 efficiency to give a big speech about why snprintf is safe, but 41 then it implicitly performs a large number of mallocs and memcpy 42 operations. 43 * page/Page.cpp: 44 (WebCore::Page::userStyleSheet): 45 * platform/chromium/support/WebHTTPLoadInfo.cpp: 46 (WebKit::addHeader): 47 * platform/chromium/support/WebURLResponse.cpp: 48 (WebKit::WebURLResponse::addHTTPHeaderField): 49 - This header-appending idiom looks like a reasonable use case for 50 String::append. 51 * xml/XMLHttpRequest.cpp: 52 (WebCore::XMLHttpRequest::send): 53 (WebCore::XMLHttpRequest::setRequestHeaderInternal): 54 * xml/XPathFunctions.cpp: 55 (WebCore::XPath::FunTranslate::evaluate): 56 - Fixes 6 year old FIXME. 57 * xml/parser/XMLDocumentParser.cpp: 58 (WebCore::XMLDocumentParser::append): 59 * xml/parser/XMLDocumentParser.h: 60 (XMLDocumentParser): 61 * xml/parser/XMLDocumentParserLibxml2.cpp: 62 (WebCore::XMLDocumentParser::doEnd): 63 * xml/parser/XMLDocumentParserQt.cpp: 64 (WebCore::XMLDocumentParser::doEnd): 65 - Changed m_originalSourceForTransform to a SegmentedString so that 66 we don't need to malloc and copy the entire document every time 67 we get more data from the network. 68 1 69 2012-09-01 Tommy Widenflycht <tommyw@google.com> 2 70 -
trunk/Source/WebCore/inspector/InspectorStyleTextEditor.cpp
r110854 r127366 105 105 } 106 106 if (!isHTMLLineBreak(m_styleText[propertyStart])) 107 textToSet += formatLineFeed;107 textToSet.append(formatLineFeed); 108 108 } else { 109 109 String fullPrefix = formatLineFeed + formatPropertyPrefix; 110 110 long fullPrefixLength = fullPrefix.length(); 111 textToSet += fullPrefix;111 textToSet.append(fullPrefix); 112 112 if (insertFirstInSource && (propertyStart < fullPrefixLength || m_styleText.substring(propertyStart - fullPrefixLength, fullPrefixLength) != fullPrefix)) 113 113 textToSet.insert(fullPrefix, formattingPrependOffset); -
trunk/Source/WebCore/inspector/NetworkResourcesData.cpp
r126926 r127366 114 114 size_t dataLength = m_dataBuffer->size(); 115 115 m_content = m_decoder->decode(m_dataBuffer->data(), m_dataBuffer->size()); 116 m_content += m_decoder->flush();116 m_content.append(m_decoder->flush()); 117 117 m_dataBuffer = nullptr; 118 118 return contentSizeInBytes(m_content) - dataLength; -
trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp
r127123 r127366 91 91 // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory 92 92 String sheetText = m_decoder->decode(m_data->data(), m_data->size()); 93 sheetText += m_decoder->flush();93 sheetText.append(m_decoder->flush()); 94 94 return sheetText; 95 95 } … … 105 105 if (m_data) { 106 106 m_decodedSheetText = m_decoder->decode(m_data->data(), m_data->size()); 107 m_decodedSheetText += m_decoder->flush();107 m_decodedSheetText.append(m_decoder->flush()); 108 108 } 109 109 setLoading(false); -
trunk/Source/WebCore/loader/cache/CachedFont.cpp
r124884 r127366 138 138 RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("application/xml"); 139 139 String svgSource = decoder->decode(m_data->data(), m_data->size()); 140 svgSource += decoder->flush();140 svgSource.append(decoder->flush()); 141 141 142 142 m_externalSVGDocument->setContent(svgSource); -
trunk/Source/WebCore/loader/cache/CachedScript.cpp
r126154 r127366 72 72 if (!m_script && m_data) { 73 73 m_script = m_decoder->decode(m_data->data(), encodedSize()); 74 m_script += m_decoder->flush();74 m_script.append(m_decoder->flush()); 75 75 setDecodedSize(m_script.sizeInBytes()); 76 76 } -
trunk/Source/WebCore/loader/cache/CachedXSLStyleSheet.cpp
r126154 r127366 70 70 return; 71 71 72 m_data = data; 72 m_data = data; 73 73 setEncodedSize(m_data.get() ? m_data->size() : 0); 74 74 if (m_data.get()) { 75 m_sheet = String(m_decoder->decode(m_data->data(), encodedSize()));76 m_sheet += m_decoder->flush();75 m_sheet = m_decoder->decode(m_data->data(), encodedSize()); 76 m_sheet.append(m_decoder->flush()); 77 77 } 78 78 setLoading(false); -
trunk/Source/WebCore/page/FrameTree.cpp
r120005 r127366 31 31 #include <wtf/Vector.h> 32 32 #include <wtf/text/CString.h> 33 #include <wtf/text/StringBuilder.h> 33 34 34 35 using std::swap; … … 151 152 chain.append(frame); 152 153 } 153 String name; 154 name += framePathPrefix; 155 if (frame) 156 name += frame->tree()->uniqueName().string().substring(framePathPrefixLength, 157 frame->tree()->uniqueName().length() - framePathPrefixLength - framePathSuffixLength); 154 StringBuilder name; 155 name.append(framePathPrefix); 156 if (frame) { 157 name.append(frame->tree()->uniqueName().string().substring(framePathPrefixLength, 158 frame->tree()->uniqueName().length() - framePathPrefixLength - framePathSuffixLength)); 159 } 158 160 for (int i = chain.size() - 1; i >= 0; --i) { 159 161 frame = chain[i]; 160 name += "/"; 161 name += frame->tree()->uniqueName(); 162 } 163 164 // Suffix buffer has more than enough space for: 165 // 10 characters before the number 166 // a number (20 digits for the largest 64-bit integer) 167 // 6 characters after the number 168 // trailing null byte 169 // But we still use snprintf just to be extra-safe. 170 char suffix[40]; 171 snprintf(suffix, sizeof(suffix), "/<!--frame%u-->-->", childCount()); 172 173 name += suffix; 174 175 return AtomicString(name); 162 name.append('/'); 163 name.append(frame->tree()->uniqueName()); 164 } 165 166 name.appendLiteral("/<!--frame"); 167 name.append(String::number(childCount())); 168 name.appendLiteral("-->-->"); 169 170 return name.toAtomicString(); 176 171 } 177 172 -
trunk/Source/WebCore/page/Page.cpp
r126968 r127366 838 838 RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/css"); 839 839 m_userStyleSheet = decoder->decode(data->data(), data->size()); 840 m_userStyleSheet += decoder->flush();840 m_userStyleSheet.append(decoder->flush()); 841 841 842 842 return m_userStyleSheet; -
trunk/Source/WebCore/platform/chromium/support/WebHTTPLoadInfo.cpp
r126926 r127366 107 107 // It is important that values are separated by '\n', not comma, otherwise Set-Cookie header is not parseable. 108 108 if (!result.isNewEntry) 109 result.iterator->second += "\n" + String(value);109 result.iterator->second.append("\n" + String(value)); 110 110 } 111 111 -
trunk/Source/WebCore/platform/chromium/support/WebURLResponse.cpp
r126926 r127366 262 262 const_cast<HTTPHeaderMap*>(&map)->add(name, valueStr); 263 263 if (!result.isNewEntry) 264 result.iterator->second += ", " + valueStr;264 result.iterator->second.append(", " + valueStr); 265 265 } 266 266 -
trunk/Source/WebCore/xml/XMLHttpRequest.cpp
r126926 r127366 645 645 String contentType = getRequestHeader("Content-Type"); 646 646 if (contentType.isEmpty()) { 647 contentType = "multipart/form-data; boundary="; 648 contentType += m_requestEntityBody->boundary().data(); 647 contentType = makeString("multipart/form-data; boundary=", m_requestEntityBody->boundary().data()); 649 648 setRequestHeaderInternal("Content-Type", contentType); 650 649 } … … 921 920 HTTPHeaderMap::AddResult result = m_requestHeaders.add(name, value); 922 921 if (!result.isNewEntry) 923 result.iterator->second += ", " + value;922 result.iterator->second.append(", " + value); 924 923 } 925 924 -
trunk/Source/WebCore/xml/XPathFunctions.cpp
r126926 r127366 551 551 String s2 = arg(1)->evaluate().toString(); 552 552 String s3 = arg(2)->evaluate().toString(); 553 String newString; 554 555 // FIXME: Building a String a character at a time is quite slow. 553 StringBuilder result; 554 556 555 for (unsigned i1 = 0; i1 < s1.length(); ++i1) { 557 556 UChar ch = s1[i1]; … … 559 558 560 559 if (i2 == notFound) 561 newString += String(&ch, 1); 562 else if (i2 < s3.length()) { 563 UChar c2 = s3[i2]; 564 newString += String(&c2, 1); 565 } 566 } 567 568 return newString; 560 result.append(ch); 561 else if (i2 < s3.length()) 562 result.append(s3[i2]); 563 } 564 565 return result.toString(); 569 566 } 570 567 -
trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp
r121560 r127366 113 113 } 114 114 115 void XMLDocumentParser::append(const SegmentedString& s) 116 { 117 String parseString = s.toString(); 118 115 void XMLDocumentParser::append(const SegmentedString& source) 116 { 119 117 if (m_sawXSLTransform || !m_sawFirstElement) 120 m_originalSourceForTransform += parseString;118 m_originalSourceForTransform.append(source); 121 119 122 120 if (isStopped() || m_sawXSLTransform) … … 124 122 125 123 if (m_parserPaused) { 126 m_pendingSrc.append(s );127 return; 128 } 129 130 doWrite( parseString);124 m_pendingSrc.append(source); 125 return; 126 } 127 128 doWrite(source.toString()); 131 129 132 130 // After parsing, go ahead and dispatch image beforeload events. -
trunk/Source/WebCore/xml/parser/XMLDocumentParser.h
r121564 r127366 178 178 FrameView* m_view; 179 179 180 S tring m_originalSourceForTransform;180 SegmentedString m_originalSourceForTransform; 181 181 182 182 #if USE(QXMLSTREAM) -
trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp
r123788 r127366 1333 1333 1334 1334 if (m_sawXSLTransform) { 1335 void* doc = xmlDocPtrForString(document()->cachedResourceLoader(), m_originalSourceForTransform , document()->url().string());1335 void* doc = xmlDocPtrForString(document()->cachedResourceLoader(), m_originalSourceForTransform.toString(), document()->url().string()); 1336 1336 document()->setTransformSource(adoptPtr(new TransformSource(doc))); 1337 1337 -
trunk/Source/WebCore/xml/parser/XMLDocumentParserQt.cpp
r123839 r127366 202 202 #if ENABLE(XSLT) 203 203 if (m_sawXSLTransform) { 204 document()->setTransformSource(adoptPtr(new TransformSource(m_originalSourceForTransform )));204 document()->setTransformSource(adoptPtr(new TransformSource(m_originalSourceForTransform.toString()))); 205 205 document()->setParsing(false); // Make the doc think it's done, so it will apply xsl sheets. 206 206 document()->styleResolverChanged(RecalcStyleImmediately);
Note: See TracChangeset
for help on using the changeset viewer.