Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Unified Diff: Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp

Issue 219153002: Optimize named property access on CSSStyleDeclaration objects (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « PerformanceTests/CSS/CSSPropertySetterGetterMethods.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp
diff --git a/Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp b/Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp
index a282c841fed5ba944cec68f62277dca98bdcc29c..d0301efca04a2945332d966b88191095db398688 100644
--- a/Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp
+++ b/Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp
@@ -84,6 +84,50 @@ struct CSSPropertyInfo {
CSSPropertyID propID;
};
+static CSSPropertyID cssResolvedPropertyID(const String& propertyName)
+{
+ unsigned length = propertyName.length();
+ if (!length)
+ return CSSPropertyInvalid;
+
+ StringBuilder builder;
+ builder.reserveCapacity(length);
+
+ unsigned i = 0;
+ bool hasSeenDash = false;
+
+ if (hasCSSPropertyNamePrefix(propertyName, "css"))
+ i += 3;
+ else if (hasCSSPropertyNamePrefix(propertyName, "webkit"))
+ builder.append('-');
+ else if (isASCIIUpper(propertyName[0]))
+ return CSSPropertyInvalid;
+
+ bool hasSeenUpper = isASCIIUpper(propertyName[i]);
+
+ builder.append(toASCIILower(propertyName[i++]));
+
+ for (; i < length; ++i) {
+ UChar c = propertyName[i];
+ if (!isASCIIUpper(c)) {
+ if (c == '-')
+ hasSeenDash = true;
+ builder.append(c);
+ } else {
+ hasSeenUpper = true;
+ builder.append('-');
+ builder.append(toASCIILower(c));
+ }
+ }
+
+ // Reject names containing both dashes and upper-case characters, such as "border-rightColor".
+ if (hasSeenDash && hasSeenUpper)
+ return CSSPropertyInvalid;
+
+ String propName = builder.toString();
+ return cssPropertyID(propName);
+}
+
// When getting properties on CSSStyleDeclarations, the name used from
// Javascript and the actual name of the property are not the same, so
// we have to do the following translation. The translation turns upper
@@ -100,54 +144,13 @@ static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName)
DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ());
CSSPropertyInfo* propInfo = map.get(propertyName);
if (!propInfo) {
- unsigned length = propertyName.length();
- if (!length)
- return 0;
-
- StringBuilder builder;
- builder.reserveCapacity(length);
-
- unsigned i = 0;
- bool hasSeenDash = false;
-
- if (hasCSSPropertyNamePrefix(propertyName, "css"))
- i += 3;
- else if (hasCSSPropertyNamePrefix(propertyName, "webkit"))
- builder.append('-');
- else if (isASCIIUpper(propertyName[0]))
- return 0;
-
- bool hasSeenUpper = isASCIIUpper(propertyName[i]);
-
- builder.append(toASCIILower(propertyName[i++]));
-
- for (; i < length; ++i) {
- UChar c = propertyName[i];
- if (!isASCIIUpper(c)) {
- if (c == '-')
- hasSeenDash = true;
- builder.append(c);
- }
- else {
- hasSeenUpper = true;
- builder.append('-');
- builder.append(toASCIILower(c));
- }
- }
-
- // Reject names containing both dashes and upper-case characters, such as "border-rightColor".
- if (hasSeenDash && hasSeenUpper)
- return 0;
-
- String propName = builder.toString();
- CSSPropertyID propertyID = cssPropertyID(propName);
- if (propertyID && RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID)) {
- propInfo = new CSSPropertyInfo();
- propInfo->propID = propertyID;
- map.add(propertyName, propInfo);
- }
+ propInfo = new CSSPropertyInfo();
+ propInfo->propID = cssResolvedPropertyID(propertyName);
+ map.add(propertyName, propInfo);
}
- return propInfo;
+ if (propInfo->propID && RuntimeCSSEnabled::isCSSPropertyEnabled(propInfo->propID))
+ return propInfo;
+ return 0;
}
void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCallbackInfo<v8::Array>& info)
« no previous file with comments | « PerformanceTests/CSS/CSSPropertySetterGetterMethods.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698