From 2439948bcc0ec9daf91cf79301195e59bad49aff Mon Sep 17 00:00:00 2001 From: Kazuki Tsujimoto Date: Tue, 19 Nov 2019 08:53:01 -0600 Subject: Avoid needless object allocation --- struct.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'struct.c') diff --git a/struct.c b/struct.c index bf1ff6f386..d1aa7c278f 100644 --- a/struct.c +++ b/struct.c @@ -957,12 +957,15 @@ rb_struct_deconstruct_keys(VALUE s, VALUE keys) rb_obj_class(keys)); } + if (RSTRUCT_LEN(s) < RARRAY_LEN(keys)) { + return rb_hash_new_with_size(0); + } h = rb_hash_new_with_size(RARRAY_LEN(keys)); for (i=0; i