[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

abarth at webkit.org abarth at webkit.org
Wed Dec 22 11:53:50 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit cc630c2b988de00cd730c5bdde216380a78faa61
Author: abarth at webkit.org <abarth at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Aug 10 23:46:54 2010 +0000

    2010-08-10  Adam Barth  <abarth at webkit.org>
    
            Reviewed by Eric Seidel.
    
            SegmentedString should keep track of how many characters it consumes
            https://bugs.webkit.org/show_bug.cgi?id=43765
    
            The easiest way to keep track of how many characters we've consumed
            would be to increment a counter every time we advance, but that's too
            slow.  Instead, we keep track lazily and update our summary durning the
            slow case of advance (which is sufficiently rare).
    
            There's some subtly to how this works w.r.t. "unconsuming" characters
            by pushing them back on the front of the segmented string.  This isn't
            really a "right answer" here because the notion of unconsuming input
            isn't present in the API.  This patch makes some assumptions about how
            clients of this class use its API.  In a future patch, we might want to
            rename some of the method names to make this more explicit.
    
            * platform/text/SegmentedString.cpp:
            (WebCore::SegmentedString::operator=):
            (WebCore::SegmentedString::append):
            (WebCore::SegmentedString::prepend):
            (WebCore::SegmentedString::advanceSubstring):
            * platform/text/SegmentedString.h:
            (WebCore::SegmentedSubstring::numberOfCharactersConsumed):
            (WebCore::SegmentedString::SegmentedString):
            (WebCore::SegmentedString::numberOfCharactersConsumed):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65100 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 33c540c..680f610 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,32 @@
+2010-08-10  Adam Barth  <abarth at webkit.org>
+
+        Reviewed by Eric Seidel.
+
+        SegmentedString should keep track of how many characters it consumes
+        https://bugs.webkit.org/show_bug.cgi?id=43765
+
+        The easiest way to keep track of how many characters we've consumed
+        would be to increment a counter every time we advance, but that's too
+        slow.  Instead, we keep track lazily and update our summary durning the
+        slow case of advance (which is sufficiently rare).
+
+        There's some subtly to how this works w.r.t. "unconsuming" characters
+        by pushing them back on the front of the segmented string.  This isn't
+        really a "right answer" here because the notion of unconsuming input
+        isn't present in the API.  This patch makes some assumptions about how
+        clients of this class use its API.  In a future patch, we might want to
+        rename some of the method names to make this more explicit.
+
+        * platform/text/SegmentedString.cpp:
+        (WebCore::SegmentedString::operator=):
+        (WebCore::SegmentedString::append):
+        (WebCore::SegmentedString::prepend):
+        (WebCore::SegmentedString::advanceSubstring):
+        * platform/text/SegmentedString.h:
+        (WebCore::SegmentedSubstring::numberOfCharactersConsumed):
+        (WebCore::SegmentedString::SegmentedString):
+        (WebCore::SegmentedString::numberOfCharactersConsumed):
+
 2010-08-10  Gavin Barraclough  <barraclough at apple.com>
 
         Rubber stamped by Sam Weinig.
diff --git a/WebCore/platform/text/SegmentedString.cpp b/WebCore/platform/text/SegmentedString.cpp
index 04d6c77..dc3f424 100644
--- a/WebCore/platform/text/SegmentedString.cpp
+++ b/WebCore/platform/text/SegmentedString.cpp
@@ -52,6 +52,7 @@ const SegmentedString& SegmentedString::operator=(const SegmentedString &other)
     else
         m_currentChar = other.m_currentChar;
     m_closed = other.m_closed;
+    m_numberOfCharactersConsumedPriorToCurrentString = other.m_numberOfCharactersConsumedPriorToCurrentString;
     return *this;
 }
 
@@ -99,6 +100,7 @@ void SegmentedString::append(const SegmentedSubstring &s)
     ASSERT(!m_closed);
     if (s.m_length) {
         if (!m_currentString.m_length) {
+            m_numberOfCharactersConsumedPriorToCurrentString += m_currentString.numberOfCharactersConsumed();
             m_currentString = s;
         } else {
             m_substrings.append(s);
@@ -110,7 +112,16 @@ void SegmentedString::append(const SegmentedSubstring &s)
 void SegmentedString::prepend(const SegmentedSubstring &s)
 {
     ASSERT(!escaped());
+    // FIXME: Add this ASSERT once we've deleted the LegacyHTMLDocumentParser.
+    // ASSERT(!s.numberOfCharactersConsumed());
     if (s.m_length) {
+        // FIXME: We're assuming that the prepend were originally consumed by
+        //        this SegmentedString.  We're also ASSERTing that s is a fresh
+        //        SegmentedSubstring.  These assumptions are sufficient for our
+        //        current use, but we might need to handle the more elaborate
+        //        cases in the future.
+        m_numberOfCharactersConsumedPriorToCurrentString += m_currentString.numberOfCharactersConsumed();
+        m_numberOfCharactersConsumedPriorToCurrentString -= s.m_length;
         if (!m_currentString.m_length)
             m_currentString = s;
         else {
@@ -160,7 +171,12 @@ void SegmentedString::prepend(const SegmentedString &s)
 void SegmentedString::advanceSubstring()
 {
     if (m_composite) {
+        m_numberOfCharactersConsumedPriorToCurrentString += m_currentString.numberOfCharactersConsumed();
         m_currentString = m_substrings.takeFirst();
+        // If we've previously consumed some characters of the non-current
+        // string, we now account for those characters as part of the current
+        // string, not as part of "prior to current string."
+        m_numberOfCharactersConsumedPriorToCurrentString -= m_currentString.numberOfCharactersConsumed();
         if (m_substrings.isEmpty())
             m_composite = false;
     } else {
diff --git a/WebCore/platform/text/SegmentedString.h b/WebCore/platform/text/SegmentedString.h
index 1d3098d..91c2cbe 100644
--- a/WebCore/platform/text/SegmentedString.h
+++ b/WebCore/platform/text/SegmentedString.h
@@ -45,6 +45,8 @@ public:
 
     void setExcludeLineNumbers() { m_doNotExcludeLineNumbers = false; }
 
+    int numberOfCharactersConsumed() const { return m_string.length() - m_length; }
+
     void appendTo(String& str) const
     {
         if (m_string.characters() == m_current) {
@@ -69,10 +71,26 @@ private:
 class SegmentedString {
 public:
     SegmentedString()
-        : m_pushedChar1(0), m_pushedChar2(0), m_currentChar(0), m_composite(false), m_closed(false) {}
+        : m_pushedChar1(0)
+        , m_pushedChar2(0)
+        , m_currentChar(0)
+        , m_numberOfCharactersConsumedPriorToCurrentString(0)
+        , m_composite(false)
+        , m_closed(false)
+    {
+    }
+
     SegmentedString(const String& str)
-        : m_pushedChar1(0), m_pushedChar2(0), m_currentString(str)
-        , m_currentChar(m_currentString.m_current), m_composite(false), m_closed(false) {}
+        : m_pushedChar1(0)
+        , m_pushedChar2(0)
+        , m_currentString(str)
+        , m_currentChar(m_currentString.m_current)
+        , m_numberOfCharactersConsumedPriorToCurrentString(0)
+        , m_composite(false)
+        , m_closed(false)
+    {
+    }
+
     SegmentedString(const SegmentedString&);
 
     const SegmentedString& operator=(const SegmentedString&);
@@ -173,6 +191,13 @@ public:
 
     bool escaped() const { return m_pushedChar1; }
 
+    int numberOfCharactersConsumed()
+    {
+        // We don't currently handle the case when there are pushed character.
+        ASSERT(!m_pushedChar1);
+        return m_numberOfCharactersConsumedPriorToCurrentString + m_currentString.numberOfCharactersConsumed();
+    }
+
     String toString() const;
 
     const UChar& operator*() const { return *current(); }
@@ -221,6 +246,7 @@ private:
     UChar m_pushedChar2;
     SegmentedSubstring m_currentString;
     const UChar* m_currentChar;
+    int m_numberOfCharactersConsumedPriorToCurrentString;
     Deque<SegmentedSubstring> m_substrings;
     bool m_composite;
     bool m_closed;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list