Skip to content

Commit 56e9eda

Browse files
committed
fix performance by caching getArgument
1 parent 7ca0996 commit 56e9eda

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

javascript/ql/lib/semmle/javascript/dataflow/Nodes.qll

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,20 @@ class InvokeNode extends DataFlow::SourceNode instanceof DataFlow::Impl::InvokeN
9292
* but the position of `z` cannot be determined, hence there are no first and second
9393
* argument nodes.
9494
*/
95-
DataFlow::Node getArgument(int i) { result = super.getArgument(i) }
95+
cached
96+
DataFlow::Node getArgument(int i) {
97+
result = super.getArgument(i) and Stages::DataFlowStage::ref()
98+
}
9699

97100
/** Gets the data flow node corresponding to an argument of this invocation. */
98-
DataFlow::Node getAnArgument() { result = super.getAnArgument() }
101+
cached
102+
DataFlow::Node getAnArgument() { result = super.getAnArgument() and Stages::DataFlowStage::ref() }
99103

100104
/** Gets the data flow node corresponding to the last argument of this invocation. */
101-
DataFlow::Node getLastArgument() { result = this.getArgument(this.getNumArgument() - 1) }
105+
cached
106+
DataFlow::Node getLastArgument() {
107+
result = this.getArgument(this.getNumArgument() - 1) and Stages::DataFlowStage::ref()
108+
}
102109

103110
/**
104111
* Gets a data flow node corresponding to an array of values being passed as

javascript/ql/lib/semmle/javascript/internal/CachedStages.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ module Stages {
145145
exists(any(DataFlow::PropRef ref).getBase())
146146
or
147147
exists(any(DataFlow::ClassNode cls))
148+
or
149+
exists(any(DataFlow::CallNode node).getArgument(_))
150+
or
151+
exists(any(DataFlow::CallNode node).getAnArgument())
152+
or
153+
exists(any(DataFlow::CallNode node).getLastArgument())
148154
}
149155
}
150156

0 commit comments

Comments
 (0)