GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add assert to ensure the same id is not added multiple times (#14325) · netty/netty@e4ef07f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • resolver-dns/src/main/java/io/netty5/resolver/dns
    • DnsQueryIdSpace.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎resolver-dns/src/main/java/io/netty5/resolver/dns/DnsQueryIdSpace.java‎

Copy file name to clipboardExpand all lines: resolver-dns/src/main/java/io/netty5/resolver/dns/DnsQueryIdSpace.java
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ int nextId() {
6161
} else if (freeIdx == -1 ||
6262
// Let's make it somehow random which free slot is used.
6363
ThreadLocalRandom.current().nextBoolean()) {
64-
// We have a slot that we can use to create a new bucket if we need to.
65-
freeIdx = bucketIdx;
64+
// We have a slot that we can use to create a new bucket if we need to.
65+
freeIdx = bucketIdx;
6666
}
6767
}
6868
if (freeIdx == -1) {
@@ -178,8 +178,15 @@ void pushId(int id) {
178178
assert id <= startId + ids.length && id >= startId;
179179
// pick a slot for our index, and whatever was in that slot before will get moved to the tail.
180180
int insertionPosition = ThreadLocalRandom.current().nextInt(count + 1);
181-
ids[count] = ids[insertionPosition];
182-
ids[insertionPosition] = (short) id;
181+
182+
short moveId = ids[insertionPosition];
183+
short insertId = (short) id;
184+
185+
// Assert that the ids are different or its the same index.
186+
assert moveId != insertId || insertionPosition == count;
187+
188+
ids[count] = moveId;
189+
ids[insertionPosition] = insertId;
183190
count++;
184191
}
185192

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.