Title: [145043] trunk/Source/WebCore
Revision
145043
Author
mk...@chromium.org
Date
2013-03-06 23:49:06 -0800 (Wed, 06 Mar 2013)

Log Message

[V8] Preprocess constant values to avoid a "static_cast<signed int>" in CodeGeneratorV8.
https://bugs.webkit.org/show_bug.cgi?id=111625

Reviewed by Kentaro Hara.

When processing constants in IDL files, CodeGeneratorV8 currently runs
the values through 'static_cast<signed int>' in the generated code. We
can avoid this miniscule bit of overhead by preprocessing the hex value
in Perl when generating the code.

The FIXME has been in the code since it originally landed in 2009[1].
Now's as good a time as any to take care of it.

[1]: http://trac.webkit.org/browser/trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm?rev=144976#L2933

* bindings/scripts/CodeGeneratorV8.pm:
(GenerateImplementation):
    If we're presented with a string which begins with '0x', run it
    through some fairly obtuse Perlisms to first convert from a hex
    string to an integer ('hex($value)'), "pack" the integer as an
    unsigned integer ('pack("I", ...)'), and then "unpack" it as a
    signed integer ('unpack("i", ...)'). Because that's _of course_
    how you would do things.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (145042 => 145043)


--- trunk/Source/WebCore/ChangeLog	2013-03-07 07:25:20 UTC (rev 145042)
+++ trunk/Source/WebCore/ChangeLog	2013-03-07 07:49:06 UTC (rev 145043)
@@ -1,3 +1,29 @@
+2013-03-06  Mike West  <mk...@chromium.org>
+
+        [V8] Preprocess constant values to avoid a "static_cast<signed int>" in CodeGeneratorV8.
+        https://bugs.webkit.org/show_bug.cgi?id=111625
+
+        Reviewed by Kentaro Hara.
+
+        When processing constants in IDL files, CodeGeneratorV8 currently runs
+        the values through 'static_cast<signed int>' in the generated code. We
+        can avoid this miniscule bit of overhead by preprocessing the hex value
+        in Perl when generating the code.
+
+        The FIXME has been in the code since it originally landed in 2009[1].
+        Now's as good a time as any to take care of it.
+
+        [1]: http://trac.webkit.org/browser/trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm?rev=144976#L2933
+
+        * bindings/scripts/CodeGeneratorV8.pm:
+        (GenerateImplementation):
+            If we're presented with a string which begins with '0x', run it
+            through some fairly obtuse Perlisms to first convert from a hex
+            string to an integer ('hex($value)'), "pack" the integer as an
+            unsigned integer ('pack("I", ...)'), and then "unpack" it as a
+            signed integer ('unpack("i", ...)'). Because that's _of course_
+            how you would do things.
+
 2013-03-06  Paweł Forysiuk  <tuxa...@o2.pl>
 
         WebKit does not build without accelerated compositing after Changeset 144823

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm (145042 => 145043)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm	2013-03-07 07:25:20 UTC (rev 145042)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm	2013-03-07 07:49:06 UTC (rev 145043)
@@ -2930,15 +2930,17 @@
         if ($attrExt->{"V8EnabledAtRuntime"}) {
             push(@constantsEnabledAtRuntime, $constant);
         } else {
-            # FIXME: we need the static_cast here only because of one constant, NodeFilter.idl
-            # defines "const unsigned long SHOW_ALL = 0xFFFFFFFF".  It would be better if we
-            # handled this here, and converted it to a -1 constant in the c++ output.
             if ($conditional) {
                 my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional);
                 push(@implContent, "#if ${conditionalString}\n");
             }
+            # If the value we're dealing with is a hex number, preprocess it into a signed integer
+            # here, rather than running static_cast<signed int> in the generated code.
+            if (substr($value, 0, 2) eq "0x") {
+              $value = unpack('i', pack('I', hex($value)));
+            }
             push(@implContent, <<END);
-    {"${name}", static_cast<signed int>($value)},
+    {"${name}", $value},
 END
             push(@implContent, "#endif\n") if $conditional;
         }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to