tuned performance: much faster low-level operation;
authorwenzelm
Sun, 26 Mar 2023 14:36:47 +0200
changeset 77712 dd4bb80dbc3a
parent 77711 25fd62cba347
child 77713 0d6e592d24c0
tuned performance: much faster low-level operation;
src/Pure/General/bytes.scala
--- a/src/Pure/General/bytes.scala	Sun Mar 26 14:24:38 2023 +0200
+++ b/src/Pure/General/bytes.scala	Sun Mar 26 14:36:47 2023 +0200
@@ -12,6 +12,7 @@
 import java.nio.ByteBuffer
 import java.nio.channels.FileChannel
 import java.nio.file.StandardOpenOption
+import java.util.Arrays
 import org.tukaani.xz
 import com.github.luben.zstd
 
@@ -118,9 +119,9 @@
   override def equals(that: Any): Boolean = {
     that match {
       case other: Bytes =>
-        if (this eq other) true
-        else if (length != other.length) false
-        else (0 until length).forall(i => bytes(offset + i) == other.bytes(other.offset + i))
+        this.eq(other) ||
+        Arrays.equals(bytes, offset, offset + length,
+          other.bytes, other.offset, other.offset + other.length)
       case _ => false
     }
   }