You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pekko.apache.org by he...@apache.org on 2026/06/23 03:14:30 UTC
(pekko) branch refactor/hexformat created (now bef27ca412)
This is an automated email from the ASF dual-hosted git repository.
He-Pin pushed a change to branch refactor/hexformat
in repository https://gitbox.apache.org/repos/asf/pekko.git
at bef27ca412 refactor: use HexFormat for hex encoding instead of manual formatting
This branch includes the following new commits:
new bef27ca412 refactor: use HexFormat for hex encoding instead of manual formatting
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pekko.apache.org
For additional commands, e-mail: commits-help@pekko.apache.org
(pekko) 01/01: refactor: use HexFormat for hex encoding instead of manual formatting
Posted by he...@apache.org.
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: 虎鸣 <he...@alibaba-inc.com>
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: commits-unsubscribe@pekko.apache.org
For additional commands, e-mail: commits-help@pekko.apache.org