From 7405ce4dab21f4d184f22b32168622804948f309 Mon Sep 17 00:00:00 2001 From: redkale Date: Sun, 20 Oct 2024 02:12:30 +0800 Subject: [PATCH] pb --- .../convert/pb/ProtobufBytesWriter.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/redkale/convert/pb/ProtobufBytesWriter.java b/src/main/java/org/redkale/convert/pb/ProtobufBytesWriter.java index 11229e728..278127bc2 100644 --- a/src/main/java/org/redkale/convert/pb/ProtobufBytesWriter.java +++ b/src/main/java/org/redkale/convert/pb/ProtobufBytesWriter.java @@ -60,7 +60,7 @@ public class ProtobufBytesWriter extends ProtobufWriter { // 存在child情况 s = p; p = p.parent; offerPool(s); - } while (p != this && p != null); + } while (p != this); } this.delegate = null; if (this.content.length > RESET_MAX_SIZE) { @@ -79,6 +79,23 @@ public class ProtobufBytesWriter extends ProtobufWriter { // 存在child情况 @Override public ProtobufWriter pollChild() { Queue queue = this.pool; + if (queue == null) { + // 必须要使用根节点的pool + ProtobufBytesWriter root = null; + if (this.parent != null) { + ProtobufWriter p = this; + while ((p = p.parent) instanceof ProtobufBytesWriter) { + root = (ProtobufBytesWriter) p; + } + } + if (root != null) { + queue = root.pool; + if (queue == null) { + root.pool = new ArrayDeque<>(CHILD_SIZE); + queue = root.pool; + } + } + } if (queue == null) { this.pool = new ArrayDeque<>(CHILD_SIZE); queue = this.pool;