Title: [156902] trunk/Source/WebCore
Revision
156902
Author
[email protected]
Date
2013-10-04 11:41:09 -0700 (Fri, 04 Oct 2013)

Log Message

Optimize strings copies in srcset parser
https://bugs.webkit.org/show_bug.cgi?id=121899

Patch by Romain Perier <[email protected]> on 2013-10-04
Reviewed by Alexey Proskuryakov.

No new tests, covered by existing ones.

* html/parser/HTMLParserIdioms.cpp:
(WebCore::parseImagesWithScaleFromSrcsetAttribute): Don't copy
image.imageURL at each loop iteration, save indexes instead.
(WebCore::bestFitSourceForImageAttributes): Make a String for
the URL only when the corresponding candidate is chosen
by the selection algorithm. It reduces the number of copies
significantly and improves performance
(around 30% with the "Release" profile and 60% with the "Debug" one).

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (156901 => 156902)


--- trunk/Source/WebCore/ChangeLog	2013-10-04 18:40:03 UTC (rev 156901)
+++ trunk/Source/WebCore/ChangeLog	2013-10-04 18:41:09 UTC (rev 156902)
@@ -1,3 +1,21 @@
+2013-10-04  Romain Perier  <[email protected]>
+
+        Optimize strings copies in srcset parser
+        https://bugs.webkit.org/show_bug.cgi?id=121899
+
+        Reviewed by Alexey Proskuryakov.
+
+        No new tests, covered by existing ones.
+
+        * html/parser/HTMLParserIdioms.cpp:
+        (WebCore::parseImagesWithScaleFromSrcsetAttribute): Don't copy
+        image.imageURL at each loop iteration, save indexes instead.
+        (WebCore::bestFitSourceForImageAttributes): Make a String for
+        the URL only when the corresponding candidate is chosen
+        by the selection algorithm. It reduces the number of copies
+        significantly and improves performance
+        (around 30% with the "Release" profile and 60% with the "Debug" one).
+
 2013-10-04  Alexey Proskuryakov  <[email protected]>
 
         Add svn:ignore to *.pyc files in inspector/Scripts directory, so that they don't

Modified: trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp (156901 => 156902)


--- trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp	2013-10-04 18:40:03 UTC (rev 156901)
+++ trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp	2013-10-04 18:41:09 UTC (rev 156902)
@@ -300,11 +300,20 @@
 #endif
 
 struct ImageWithScale {
-    String imageURL;
+    unsigned imageURLStart;
+    unsigned imageURLLength;
     float scaleFactor;
-    bool operator==(const ImageWithScale& image) const
+
+    ImageWithScale()
+        : imageURLStart(0)
+        , imageURLLength(0)
+        , scaleFactor(1)
+    { 
+    }
+
+    bool hasImageURL() const
     {
-        return scaleFactor == image.scaleFactor && imageURL == image.imageURL;
+        return imageURLLength;
     }
 };
 typedef Vector<ImageWithScale> ImageCandidates;
@@ -390,7 +399,8 @@
             }
         }
         ImageWithScale image;
-        image.imageURL = String(srcsetAttribute.characters() + imageURLStart, imageURLEnd - imageURLStart);
+        image.imageURLStart = imageURLStart;
+        image.imageURLLength = imageURLEnd - imageURLStart;
         image.scaleFactor = imageScaleFactor;
 
         imageCandidates.append(image);
@@ -406,11 +416,8 @@
     parseImagesWithScaleFromSrcsetAttribute(srcsetAttribute, imageCandidates);
 
     if (!srcAttribute.isEmpty()) {
-        ImageWithScale image;
-        image.imageURL = srcAttribute;
-        image.scaleFactor = 1.0;
-
-        imageCandidates.append(image);
+        ImageWithScale srcPlaceholderImage;
+        imageCandidates.append(srcPlaceholderImage);
     }
 
     if (imageCandidates.isEmpty())
@@ -420,9 +427,10 @@
 
     for (size_t i = 0; i < imageCandidates.size() - 1; ++i) {
         if (imageCandidates[i].scaleFactor >= deviceScaleFactor)
-            return String(imageCandidates[i].imageURL);
+            return imageCandidates[i].hasImageURL() ? srcsetAttribute.substringSharingImpl(imageCandidates[i].imageURLStart, imageCandidates[i].imageURLLength) : srcAttribute;
     }
-    return String(imageCandidates.last().imageURL);
+    const ImageWithScale& lastCandidate = imageCandidates.last();
+    return lastCandidate.hasImageURL() ? srcsetAttribute.substringSharingImpl(lastCandidate.imageURLStart, lastCandidate.imageURLLength) : srcAttribute;
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to