From 4e71f8009acdb44c8fc78eb27de768f45262224a Mon Sep 17 00:00:00 2001 From: redkale Date: Wed, 2 Oct 2024 00:50:40 +0800 Subject: [PATCH] protobuf --- .../org/redkale/convert/pb/ProtobufWriter.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/redkale/convert/pb/ProtobufWriter.java b/src/main/java/org/redkale/convert/pb/ProtobufWriter.java index 624c70b9e..876f3885f 100644 --- a/src/main/java/org/redkale/convert/pb/ProtobufWriter.java +++ b/src/main/java/org/redkale/convert/pb/ProtobufWriter.java @@ -130,14 +130,13 @@ public class ProtobufWriter extends Writer implements ByteTuple { protected boolean recycle() { super.recycle(); if (this.delegate != null && this.pool != null) { - List list = new ArrayList<>(); - ProtobufWriter next = this; - while ((next = next.child) != null) { - list.add(next); - } - for (ProtobufWriter item : list) { - offerPool(item); - } + ProtobufWriter s; + ProtobufWriter p = this.delegate; + do { + s = p; + p = p.parent; + offerPool(s); + } while (p != this); } this.parent = null; this.child = null; @@ -169,7 +168,7 @@ public class ProtobufWriter extends Writer implements ByteTuple { } ProtobufWriter result = queue.poll(); if (result == null) { - result = new ProtobufWriter(); + result = new ProtobufWriter(new byte[256], 0); } if (delegate == null) { result.parent = this;