You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/10/27 09:12:27 UTC
[shardingsphere] branch master updated: Avoid create redundant
DateTimeFormatter instance (#13311)
This is an automated email from the ASF dual-hosted git repository.
wuweijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 684c903 Avoid create redundant DateTimeFormatter instance (#13311)
684c903 is described below
commit 684c9032a545bad89e4e685684a67b3659e3ec36
Author: Cheng Pan <ch...@apache.org>
AuthorDate: Wed Oct 27 17:11:45 2021 +0800
Avoid create redundant DateTimeFormatter instance (#13311)
---
.../packet/command/query/text/MySQLTextResultSetRowPacket.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/text/MySQLTextResultSetRowPacket.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/text/MySQLTextResultSetRowPacket.java
index 366f3e9..c1b6f1c 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/text/MySQLTextResultSetRowPacket.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/text/MySQLTextResultSetRowPacket.java
@@ -39,7 +39,9 @@ import java.util.Collection;
public final class MySQLTextResultSetRowPacket implements MySQLPacket {
private static final int NULL = 0xfb;
-
+
+ private static final DateTimeFormatter DT_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
private final int sequenceId;
private final Collection<Object> data;
@@ -67,8 +69,7 @@ public final class MySQLTextResultSetRowPacket implements MySQLPacket {
} else if (each instanceof Boolean) {
payload.writeBytesLenenc((Boolean) each ? new byte[]{1} : new byte[]{0});
} else if (each instanceof LocalDateTime) {
- payload.writeStringLenenc(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.parse(each.toString(),
- DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"))));
+ payload.writeStringLenenc(DT_FMT.format((LocalDateTime) each));
} else {
payload.writeStringLenenc(each.toString());
}