diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2024-11-11 21:10:19 +0000 |
---|---|---|
committer | Gerrit Code Review <support@gerrithub.io> | 2024-11-11 21:10:19 +0000 |
commit | ea4ac5e47db1a637af4e51854172502232d862ca (patch) | |
tree | 9a047df42c817404b78be2d4a1abd9b0ca0e55f7 | |
parent | c6e8edb5ebf65b372e67bcfa041f742e82c06188 (diff) | |
parent | 20d0bfbb348674a65b6c84826b549ab22ff22c13 (diff) | |
download | jgit-ea4ac5e47db1a637af4e51854172502232d862ca.tar.gz jgit-ea4ac5e47db1a637af4e51854172502232d862ca.zip |
Merge "ssh: Minor simplification in SerialRangeSet"
-rw-r--r-- | org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/signing/ssh/SerialRangeSet.java | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/signing/ssh/SerialRangeSet.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/signing/ssh/SerialRangeSet.java index 6a0cec8821..f4eb884239 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/signing/ssh/SerialRangeSet.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/signing/ssh/SerialRangeSet.java @@ -9,7 +9,6 @@ */ package org.eclipse.jgit.internal.signing.ssh; -import java.util.SortedMap; import java.util.TreeMap; import org.eclipse.jgit.internal.transport.sshd.SshdText; @@ -50,14 +49,14 @@ class SerialRangeSet { } } - // We use the same data structure as OpenSSH,; basically a - // TreeSet<SerialRange> of mutable elements. To get "mutability", the set is - // implemented as a TreeMap with the same elements as keys and values. + // We use the same data structure as OpenSSH; basically a TreeSet of mutable + // SerialRanges. To get "mutability", the set is implemented as a TreeMap + // with the same elements as keys and values. // // get(x) will return null if none of the serial numbers in the range x is // in the set, and some range (partially) overlapping with x otherwise. // - // containsKey will return true if there is any (partially) overlapping + // containsKey(x) will return true if there is any (partially) overlapping // range in the TreeMap. private final TreeMap<SerialRange, SerialRange> ranges = new TreeMap<>( SerialRangeSet::compare); @@ -117,21 +116,15 @@ class SerialRangeSet { } // No overlapping range exists: check for coalescing with the // previous/next range - SortedMap<SerialRange, SerialRange> head = ranges.headMap(newRange); - if (!head.isEmpty()) { - SerialRange prev = head.lastKey(); - if (newRange.from() - prev.to() == 1) { - ranges.remove(prev); - newRange = new Range(prev.from(), newRange.to()); - } + SerialRange prev = ranges.floorKey(newRange); + if (prev != null && newRange.from() - prev.to() == 1) { + ranges.remove(prev); + newRange = new Range(prev.from(), newRange.to()); } - SortedMap<SerialRange, SerialRange> tail = ranges.tailMap(newRange); - if (!tail.isEmpty()) { - SerialRange next = tail.firstKey(); - if (next.from() - newRange.to() == 1) { - ranges.remove(next); - newRange = new Range(newRange.from(), next.to()); - } + SerialRange next = ranges.ceilingKey(newRange); + if (next != null && next.from() - newRange.to() == 1) { + ranges.remove(next); + newRange = new Range(newRange.from(), next.to()); } ranges.put(newRange, newRange); } |