File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,18 @@ ASTNode getAnASTNodeWithAFeature(Function f) {
127
127
result = getAnASTNodeToFeaturize ( f )
128
128
}
129
129
130
+ /** Returns the number of source-code characters in a function. */
131
+ int getNumCharsInFunction ( Function f ) {
132
+ result =
133
+ strictsum ( ASTNode node | node = getAnASTNodeWithAFeature ( f ) | getTokenizedAstNode ( node ) .length ( ) )
134
+ }
135
+
136
+ /**
137
+ * The maximum number of characters a feature can be.
138
+ * The evaluator string limit is 5395415 characters. We choose a limit lower than this.
139
+ */
140
+ private int getMaxChars ( ) { result = 1000000 }
141
+
130
142
/**
131
143
* Returns a featurized representation of the function that can be used to populate the
132
144
* `enclosingFunctionBody` feature for an endpoint.
@@ -141,6 +153,9 @@ string getBodyTokensFeature(Function function) {
141
153
node = getAnASTNodeToFeaturize ( function ) and
142
154
exists ( getTokenizedAstNode ( node ) )
143
155
) <= 256 and
156
+ // Performance optimization: If a function has more than getMaxChars() characters in its body subtokens,
157
+ // then featurize it as absent.
158
+ getNumCharsInFunction ( function ) <= getMaxChars ( ) and
144
159
result =
145
160
strictconcat ( Location l , string token |
146
161
// The use of a nested exists here allows us to avoid duplicates due to two AST nodes in the
You can’t perform that action at this time.
0 commit comments