Apache Lucene open-source search software
Override single byte writes to OutputStreamIndexOutput to remove locking (#13543)
Armin Braun9e04cb9c41bc
diff --git a/lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.java b/lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.javaindex 5c3b4dbd88a..14b56a67e8a 100644--- a/lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.java+++ b/lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.java@@ -135,5 +135,19 @@ public class OutputStreamIndexOutput extends IndexOutput {BitUtil.VH_LE_LONG.set(buf, count, i);count += Long.BYTES;}++ @Override+ public void write(int b) throws IOException {+ // override single byte write to avoid synchronization overhead now that JEP374 removed biased+ // locking+ byte[] buffer = buf;+ int count = this.count;+ if (count >= buffer.length) {+ super.write(b);+ } else {+ buffer[count] = (byte) b;+ this.count = count + 1;+ }+ }}}