Avoid copying closed variables vector; actually use move semantics
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Jun 2014 18:48:56 +0000 (18:48 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Jun 2014 18:48:56 +0000 (18:48 +0000)
Rubber-stamped by Oliver Hunt.

Currently we always copy the closed variables vector passed by Parser::closedVariables()
to ProgramNode::setClosedVariables() because these member functions return and take a const
rvalue reference, respectively. Instead, these member functions should take an return a non-
constant rvalue reference so that we actually move the closed variables vector from the Parser
object to the Node object.

* parser/Nodes.cpp:
(JSC::ProgramNode::setClosedVariables): Remove const qualifier for argument.
* parser/Nodes.h:
(JSC::ScopeNode::setClosedVariables): Ditto.
* parser/Parser.h:
(JSC::Parser::closedVariables): Remove const qualifier on return type.
(JSC::parse): Remove extraneous call to std::move(). Calling std::move() is unnecessary here
because Parser::closedVariables() returns an rvalue reference.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@170594 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/parser/Nodes.cpp
Source/JavaScriptCore/parser/Nodes.h
Source/JavaScriptCore/parser/Parser.h

index 6007579..1f9842f 100644 (file)
@@ -1,3 +1,24 @@
+2014-06-30  Daniel Bates  <dabates@apple.com>
+
+        Avoid copying closed variables vector; actually use move semantics
+
+        Rubber-stamped by Oliver Hunt.
+
+        Currently we always copy the closed variables vector passed by Parser::closedVariables()
+        to ProgramNode::setClosedVariables() because these member functions return and take a const
+        rvalue reference, respectively. Instead, these member functions should take an return a non-
+        constant rvalue reference so that we actually move the closed variables vector from the Parser
+        object to the Node object.
+
+        * parser/Nodes.cpp:
+        (JSC::ProgramNode::setClosedVariables): Remove const qualifier for argument.
+        * parser/Nodes.h:
+        (JSC::ScopeNode::setClosedVariables): Ditto.
+        * parser/Parser.h:
+        (JSC::Parser::closedVariables): Remove const qualifier on return type.
+        (JSC::parse): Remove extraneous call to std::move(). Calling std::move() is unnecessary here
+        because Parser::closedVariables() returns an rvalue reference.
+
 2014-06-30  Joseph Pecoraro  <pecoraro@apple.com>
 
         JSContext Inspection: Provide a way to use a non-Main RunLoop for Inspector JavaScript Evaluations
index 2da148f..c3ae587 100644 (file)
@@ -133,7 +133,7 @@ PassRefPtr<ProgramNode> ProgramNode::create(VM* vm, const JSTokenLocation& start
 }
 
 
-void ProgramNode::setClosedVariables(const Vector<RefPtr<StringImpl>>&& closedVariables)
+void ProgramNode::setClosedVariables(Vector<RefPtr<StringImpl>>&& closedVariables)
 {
     m_closedVariables = std::move(closedVariables);
 }
index 996d67c..a3b4153 100644 (file)
@@ -1449,7 +1449,7 @@ namespace JSC {
 
         void emitStatementsBytecode(BytecodeGenerator&, RegisterID* destination);
         
-        void setClosedVariables(const Vector<RefPtr<StringImpl>>&&) { }
+        void setClosedVariables(Vector<RefPtr<StringImpl>>&&) { }
 
     protected:
         void setSource(const SourceCode& source) { m_source = source; }
@@ -1479,7 +1479,7 @@ namespace JSC {
 
         static const bool scopeIsFunction = false;
 
-        void setClosedVariables(const Vector<RefPtr<StringImpl>>&&);
+        void setClosedVariables(Vector<RefPtr<StringImpl>>&&);
         const Vector<RefPtr<StringImpl>>& closedVariables() const { return m_closedVariables; }
     private:
         ProgramNode(VM*, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, unsigned endColumn, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
index 5409580..11d2661 100644 (file)
@@ -401,7 +401,7 @@ public:
     PassRefPtr<ParsedNode> parse(ParserError&, bool needReparsingAdjustment);
 
     JSTextPosition positionBeforeLastNewline() const { return m_lexer->positionBeforeLastNewline(); }
-    const Vector<RefPtr<StringImpl>>&& closedVariables() { return std::move(m_closedVariables); }
+    Vector<RefPtr<StringImpl>>&& closedVariables() { return std::move(m_closedVariables); }
 
 private:
     struct AllowInOverride {
@@ -951,7 +951,7 @@ PassRefPtr<ParsedNode> parse(VM* vm, const SourceCode& source, FunctionParameter
             if (!result)
                 WTF::dataLog("Error compiling builtin: ", error.m_message, "\n");
             RELEASE_ASSERT(result);
-            result->setClosedVariables(std::move(parser.closedVariables()));
+            result->setClosedVariables(parser.closedVariables());
         }
         return result.release();
     }