Skip to content

Commit 919330f

Browse files
author
Max Schaefer
committed
Some more performance refactoring.
1 parent bb63fcd commit 919330f

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

java/ql/automodel/src/AutomodelApplicationModeExtractNegativeExamples.ql

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,39 @@ Endpoint getSampleForCharacteristic(EndpointCharacteristic c, int limit) {
4040
)
4141
}
4242

43-
from
44-
Endpoint endpoint, EndpointCharacteristic characteristic, float confidence, string message,
45-
ApplicationModeMetadataExtractor meta, DollarAtString package, DollarAtString type,
46-
DollarAtString subtypes, DollarAtString name, DollarAtString signature, DollarAtString input,
47-
DollarAtString output, DollarAtString isVarargsArray, DollarAtString extensibleType
48-
where
49-
endpoint = getSampleForCharacteristic(characteristic, 100) and
43+
predicate candidate(
44+
Endpoint endpoint, EndpointCharacteristic characteristic, float confidence, string package,
45+
string type, string subtypes, string name, string signature, string input, string output,
46+
string isVarargsArray, string extensibleType
47+
) {
5048
// the node is know not to be an endpoint of any appropriate type
5149
forall(EndpointType tp | tp = endpoint.getAPotentialType() |
5250
characteristic.hasImplications(tp, false, _)
5351
) and
5452
// the lowest confidence across all endpoint types should be at least highConfidence
5553
confidence = min(float c | characteristic.hasImplications(endpoint.getAPotentialType(), false, c)) and
5654
confidence >= SharedCharacteristics::highConfidence() and
57-
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input, output,
58-
isVarargsArray, _, extensibleType) and
55+
any(ApplicationModeMetadataExtractor meta)
56+
.hasMetadata(endpoint, package, type, subtypes, name, signature, input, output,
57+
isVarargsArray, _, extensibleType) and
5958
// It's valid for a node to be both a potential source/sanitizer and a sink. We don't want to include such nodes
6059
// as negative examples in the prompt, because they're ambiguous and might confuse the model, so we explicitly them here.
6160
not exists(EndpointCharacteristic characteristic2, float confidence2, EndpointType type2 |
6261
characteristic2.appliesToEndpoint(endpoint) and
6362
confidence2 >= SharedCharacteristics::maximalConfidence() and
6463
characteristic2.hasImplications(type2, true, confidence2)
65-
) and
64+
)
65+
}
66+
67+
from
68+
Endpoint endpoint, EndpointCharacteristic characteristic, float confidence, string message,
69+
DollarAtString package, DollarAtString type, DollarAtString subtypes, DollarAtString name,
70+
DollarAtString signature, DollarAtString input, DollarAtString output,
71+
DollarAtString isVarargsArray, DollarAtString extensibleType
72+
where
73+
endpoint = getSampleForCharacteristic(characteristic, 100) and
74+
candidate(endpoint, characteristic, confidence, package, type, subtypes, name, signature, input,
75+
output, isVarargsArray, extensibleType) and
6676
message = characteristic
6777
select endpoint.asNode(),
6878
message + "\nrelated locations: $@, $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@.", //

0 commit comments

Comments
 (0)