From a071078e907af99db737799410d713d5ec953eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Hasi=C5=84ski?= Date: Sun, 11 Jan 2026 03:45:44 +0100 Subject: [PATCH] pack.c: remove wasted allocation in BER integer packing The 'w' format (BER compressed integer) was allocating an empty string with rb_str_new(0, 0) then immediately overwriting it with the correctly-sized allocation. Remove the wasted first allocation. ~50% improvement on BER pack benchmarks. --- pack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack.c b/pack.c index 87a5c67871..2ef826b0e2 100644 --- a/pack.c +++ b/pack.c @@ -736,7 +736,7 @@ pack_pack(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer) case 'w': /* BER compressed integer */ while (len-- > 0) { - VALUE buf = rb_str_new(0, 0); + VALUE buf; size_t numbytes; int sign; char *cp;