Changeset 82332 in webkit


Ignore:
Timestamp:
Mar 29, 2011 3:10:11 PM (13 years ago)
Author:
eae@chromium.org
Message:

2011-03-29 Emil A Eklund <eae@chromium.org>

Reviewed by Dimitri Glazkov.

DatasetDOMStringMap::item and ::contains copies attribute name string
https://bugs.webkit.org/show_bug.cgi?id=55645

  • fast/dom/script-tests/dataset-expected.txt:
  • fast/dom/script-tests/dataset.js:

Added extra test cases for getting fields by property name.

2011-03-29 Emil A Eklund <eae@chromium.org>

Reviewed by Dimitri Glazkov.

DatasetDOMStringMap::item and ::contains copies attribute name string
https://bugs.webkit.org/show_bug.cgi?id=55645

Change propertyNameMatchesAttributeName to match without creating a copy
of the string.

  • dom/DatasetDOMStringMap.cpp: (WebCore::propertyNameMatchesAttributeName):
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r82331 r82332  
     12011-03-29  Emil A Eklund  <eae@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        DatasetDOMStringMap::item and ::contains copies attribute name string
     6        https://bugs.webkit.org/show_bug.cgi?id=55645
     7
     8        * fast/dom/script-tests/dataset-expected.txt:
     9        * fast/dom/script-tests/dataset.js:
     10            Added extra test cases for getting fields by property name.
     11
    1122011-03-29  Adam Barth  <abarth@webkit.org>
    213
  • trunk/LayoutTests/fast/dom/dataset-expected.txt

    r62215 r82332  
    99PASS testGet('data--foo', 'Foo') is true
    1010PASS testGet('data---foo', '-Foo') is true
     11PASS testGet('data---foo--bar', '-Foo-Bar') is true
     12PASS testGet('data---foo---bar', '-Foo--Bar') is true
     13PASS testGet('data-foo-', 'foo-') is true
     14PASS testGet('data-foo--', 'foo--') is true
    1115PASS testGet('data-Foo', 'foo') is true
    1216PASS testGet('data-', '') is true
  • trunk/LayoutTests/fast/dom/script-tests/dataset.js

    r62215 r82332  
    1313shouldBeTrue("testGet('data--foo', 'Foo')");
    1414shouldBeTrue("testGet('data---foo', '-Foo')");
     15shouldBeTrue("testGet('data---foo--bar', '-Foo-Bar')");
     16shouldBeTrue("testGet('data---foo---bar', '-Foo--Bar')");
     17shouldBeTrue("testGet('data-foo-', 'foo-')");
     18shouldBeTrue("testGet('data-foo--', 'foo--')");
    1519shouldBeTrue("testGet('data-Foo', 'foo')"); // HTML lowercases all attributes.
    1620shouldBeTrue("testGet('data-', '')");
  • trunk/Source/WebCore/ChangeLog

    r82315 r82332  
     12011-03-29  Emil A Eklund  <eae@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        DatasetDOMStringMap::item and ::contains copies attribute name string
     6        https://bugs.webkit.org/show_bug.cgi?id=55645
     7
     8        Change propertyNameMatchesAttributeName to match without creating a copy
     9        of the string.
     10
     11        * dom/DatasetDOMStringMap.cpp:
     12        (WebCore::propertyNameMatchesAttributeName):
     13
    1142011-03-29  Csaba Osztrogonác  <ossy@webkit.org>
    215
  • trunk/Source/WebCore/dom/DatasetDOMStringMap.cpp

    r62215 r82332  
    7373static bool propertyNameMatchesAttributeName(const String& propertyName, const String& attributeName)
    7474{
    75     // FIXME: This should be able to match without creating a new string.
    76 
    77     if (!isValidAttributeName(attributeName))
     75    if (!attributeName.startsWith("data-"))
    7876        return false;
    7977
    80     String convertedName = convertAttributeNameToPropertyName(attributeName);
    81     return (convertedName == propertyName);
     78    const UChar* property = propertyName.characters();
     79    const UChar* attribute = attributeName.characters();
     80    unsigned propertyLength = propertyName.length();
     81    unsigned attributeLength = attributeName.length();
     82   
     83    unsigned a = 5;
     84    unsigned p = 0;
     85    bool wordBoundary = false;
     86    while (a < attributeLength && p < propertyLength) {
     87        if (attribute[a] == '-' && a + 1 < attributeLength && attribute[a + 1] != '-')
     88            wordBoundary = true;
     89        else {
     90            if ((wordBoundary ? toASCIIUpper(attribute[a]) : attribute[a]) != property[p])
     91                return false;
     92            p++;
     93            wordBoundary = false;
     94        }
     95        a++;
     96    }
     97
     98    return (a == attributeLength && p == propertyLength);
    8299}
    83100
Note: See TracChangeset for help on using the changeset viewer.