This is an automated email from the ASF dual-hosted git repository. He-Pin pushed a commit to branch refactor/hexformat in repository https://gitbox.apache.org/repos/asf/pekko.git
commit bef27ca41288f70150979a8f031b1f8556ea1b42 Author: 虎鸣 <[email protected]> AuthorDate: Tue Jun 23 11:14:16 2026 +0800 refactor: use HexFormat for hex encoding instead of manual formatting Motivation: Manual per-byte hex encoding with "%02x".format() is verbose and allocates a String per byte. JDK 17's HexFormat formats entire byte arrays in one call. Modification: - VectorClock.scala: replace digester.digest.map("%02x".format).mkString with HexFormat.of().formatHex(digester.digest()) - TcpFraming.scala: replace .map("%02x".format).mkString(" ") with HexFormat.ofDelimiter(" ").formatHex(bytes.toArray) Result: More concise code, fewer allocations (one String vs N+1 Strings), standard JDK API for hex encoding. Tests: sbt "cluster/compile" "remote/compile" — passed References: Refs #3136 --- cluster/src/main/scala/org/apache/pekko/cluster/VectorClock.scala | 4 +--- .../main/scala/org/apache/pekko/remote/artery/tcp/TcpFraming.scala | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cluster/src/main/scala/org/apache/pekko/cluster/VectorClock.scala b/cluster/src/main/scala/org/apache/pekko/cluster/VectorClock.scala index 06e2efcd3b..10d3a9da06 100644 --- a/cluster/src/main/scala/org/apache/pekko/cluster/VectorClock.scala +++ b/cluster/src/main/scala/org/apache/pekko/cluster/VectorClock.scala @@ -40,9 +40,7 @@ private[cluster] object VectorClock { private def hash(name: String): String = { val digester = MessageDigest.getInstance("MD5") digester.update(name.getBytes(StandardCharsets.UTF_8)) - digester.digest.map { h => - "%02x".format(0xFF & h) - }.mkString + java.util.HexFormat.of().formatHex(digester.digest()) } } diff --git a/remote/src/main/scala/org/apache/pekko/remote/artery/tcp/TcpFraming.scala b/remote/src/main/scala/org/apache/pekko/remote/artery/tcp/TcpFraming.scala index fbf72fffb0..6aca0ddd95 100644 --- a/remote/src/main/scala/org/apache/pekko/remote/artery/tcp/TcpFraming.scala +++ b/remote/src/main/scala/org/apache/pekko/remote/artery/tcp/TcpFraming.scala @@ -85,7 +85,7 @@ import pekko.util.ByteString else throw new FramingException( "Stream didn't start with expected magic bytes, " + - s"got [${(magic ++ reader.remainingData).take(10).map("%02x".format(_)).mkString(" ")}] " + + s"got [${java.util.HexFormat.ofDelimiter(" ").formatHex((magic ++ reader.remainingData).take(10).toArray)}] " + "Connection is rejected. Probably invalid accidental access.") } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
