9
9
*/
10
10
package org .truffleruby .stdlib ;
11
11
12
- import java .util .ArrayList ;
13
- import java .util .List ;
12
+ import java .util .HashMap ;
14
13
import java .util .Map ;
15
14
16
15
import org .jcodings .specific .UTF8Encoding ;
@@ -60,14 +59,14 @@ public abstract static class CoverageResultNode extends CoreMethodArrayArguments
60
59
@ TruffleBoundary
61
60
@ Specialization
62
61
protected RubyArray resultArray () {
63
- final List <RubyArray > results = new ArrayList <>();
64
62
65
63
final Map <Source , long []> counts = getContext ().getCoverageManager ().getCounts ();
66
64
67
65
if (counts == null ) {
68
66
throw new RaiseException (getContext (), coreExceptions ().runtimeErrorCoverageNotEnabled (this ));
69
67
}
70
68
69
+ Map <String , RubyArray > results = new HashMap <>();
71
70
for (Map .Entry <Source , long []> source : counts .entrySet ()) {
72
71
final long [] countsArray = source .getValue ();
73
72
@@ -81,16 +80,18 @@ protected RubyArray resultArray() {
81
80
}
82
81
}
83
82
84
- results .add (createArray (new Object []{
83
+ final String path = RubyContext .getPath (source .getKey ());
84
+ assert !results .containsKey (path ) : "path already exists in coverage results" ;
85
+ results .put (path , createArray (new Object []{
85
86
makeStringNode .executeMake (
86
- RubyContext . getPath ( source . getKey ()) ,
87
+ path ,
87
88
UTF8Encoding .INSTANCE ,
88
89
CodeRange .CR_UNKNOWN ),
89
90
createArray (countsStore )
90
91
}));
91
92
}
92
93
93
- return createArray (results .toArray ());
94
+ return createArray (results .values (). toArray ());
94
95
}
95
96
96
97
}
0 commit comments