Skip to content

Commit 5674972

Browse files
ctf: improve integerdeclaration
Clean up the hashcode. Fix a corner case in getMappings Change-Id: Iec698c9761fde045a0b9945e65ebcda97fa99cb4 Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
1 parent 6a47048 commit 5674972

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IntegerDeclaration.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -564,16 +564,7 @@ private long read(BitBuffer input) throws CTFException {
564564

565565
@Override
566566
public int hashCode() {
567-
final int prime = 31;
568-
int result = 1;
569-
result = prime * result + (int) (fAlignment ^ (fAlignment >>> 32));
570-
result = prime * result + fBase;
571-
result = prime * result + fByteOrder.toString().hashCode();
572-
result = prime * result + fClock.hashCode();
573-
result = prime * result + fEncoding.hashCode();
574-
result = prime * result + fLength;
575-
result = prime * result + (fSigned ? 1231 : 1237);
576-
return result;
567+
return Objects.hash(fAlignment, fBase, fByteOrder, fClock, fEncoding, fLength, fSigned, fMappings, getRole());
577568
}
578569

579570
@Override
@@ -645,13 +636,10 @@ String getMappingForValue(long value) {
645636
if (fIntervalTree.isEmpty()) {
646637
return ""; //$NON-NLS-1$
647638
}
648-
649639
List<String> matches = new ArrayList<>();
650-
651640
// Binary search for rightmost node with start <= value
652641
int left = 0, right = fIntervalTree.size() - 1;
653642
int lastValid = -1;
654-
655643
while (left <= right) {
656644
int mid = (left + right) / 2;
657645
if (fIntervalTree.get(mid).start <= value) {
@@ -661,16 +649,13 @@ String getMappingForValue(long value) {
661649
right = mid - 1;
662650
}
663651
}
664-
665652
// Check all nodes from lastValid backwards for overlaps
666653
for (int i = lastValid; i >= 0; i--) {
667654
IntervalNode node = fIntervalTree.get(i);
668-
if (node.end < value) {
669-
break;
655+
if (node.end >= value) {
656+
matches.add(node.name);
670657
}
671-
matches.add(node.name);
672658
}
673-
674659
return matches.isEmpty() ? "" : Objects.requireNonNull(String.join(" ", matches)); //$NON-NLS-1$ //$NON-NLS-2$
675660
}
676661

0 commit comments

Comments
 (0)