diff --git a/infer/src/cost/costModels.ml b/infer/src/cost/costModels.ml index 2d68f1fca..9f62938c8 100644 --- a/infer/src/cost/costModels.ml +++ b/infer/src/cost/costModels.ml @@ -303,6 +303,8 @@ module Call = struct $+...$--> BoundsOfCollection.linear_length ~of_function:"Iterable.forEach" ; +PatternMatch.Java.implements_map &:: "forEach" $ capt_exp $+...$--> BoundsOfCollection.linear_length ~of_function:"Map.forEach" + ; +PatternMatch.Java.implements_map &:: "containsValue" $ capt_exp + $+...$--> BoundsOfCollection.linear_length ~of_function:"Map.containsValue" ; +PatternMatch.Java.implements_collections &:: "fill" <>$ capt_exp $+...$--> BoundsOfCollection.linear_length ~of_function:"Collections.fill" diff --git a/infer/tests/codetoanalyze/java/performance/MapTest.java b/infer/tests/codetoanalyze/java/performance/MapTest.java index e87ab9a2a..4dc0190b8 100644 --- a/infer/tests/codetoanalyze/java/performance/MapTest.java +++ b/infer/tests/codetoanalyze/java/performance/MapTest.java @@ -27,4 +27,8 @@ class MapTest { newmap.putAll(map); for (Integer name : newmap.values()) {} } + + boolean containsNullValue_linear(HashMap keyMap) { + return keyMap.containsValue(null); + } } diff --git a/infer/tests/codetoanalyze/java/performance/cost-issues.exp b/infer/tests/codetoanalyze/java/performance/cost-issues.exp index 099f09fdf..ea096e805 100644 --- a/infer/tests/codetoanalyze/java/performance/cost-issues.exp +++ b/infer/tests/codetoanalyze/java/performance/cost-issues.exp @@ -301,6 +301,7 @@ codetoanalyze/java/performance/Loops.java, codetoanalyze.java.performance.Loops. codetoanalyze/java/performance/Loops.java, codetoanalyze.java.performance.Loops.unboundedSymbol_FP():void, ⊤, OnUIThread:false, [Unbounded value x,Call to void Loops.loop_linear(int),Loop] codetoanalyze/java/performance/Loops.java, codetoanalyze.java.performance.Loops.zeropad_linear_FN(java.lang.String,java.lang.String):void, 17, OnUIThread:false, [] codetoanalyze/java/performance/MapTest.java, MapTest.(), 2, OnUIThread:false, [] +codetoanalyze/java/performance/MapTest.java, MapTest.containsNullValue_linear(java.util.HashMap):boolean, 4 + keyMap.length, OnUIThread:false, [{keyMap.length},Modeled call to Map.containsValue] codetoanalyze/java/performance/MapTest.java, MapTest.entrySet_linear(java.util.Map):void, 8 + 8 ⋅ map.length + 3 ⋅ (map.length + 1), OnUIThread:false, [{map.length + 1},Loop,{map.length},Loop] codetoanalyze/java/performance/MapTest.java, MapTest.keySet_linear(java.util.Map):void, 8 + 8 ⋅ map.length + 3 ⋅ (map.length + 1), OnUIThread:false, [{map.length + 1},Loop,{map.length},Loop] codetoanalyze/java/performance/MapTest.java, MapTest.putAll_linear(java.util.Map):void, 14 + 8 ⋅ map.length + 3 ⋅ (map.length + 1), OnUIThread:false, [{map.length + 1},Loop,{map.length},Loop]