summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
authorKazuki Tsujimoto <kazuki@callcc.net>2019-11-19 08:53:01 -0600
committerKazuki Tsujimoto <kazuki@callcc.net>2019-11-19 08:53:01 -0600
commit2439948bcc0ec9daf91cf79301195e59bad49aff (patch)
tree9603e001e41d33d231479ac6e1d63068ef56a033 /struct.c
parent822d7ae31659e4ab60c4d1aa6d088577d6bc74b0 (diff)
Avoid needless object allocation
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c5
1 files changed, 4 insertions, 1 deletions
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<RARRAY_LEN(keys); i++) {
VALUE key = RARRAY_AREF(keys, i);
int i = rb_struct_pos(s, &key);
if (i < 0) {
- return rb_hash_new_with_size(0);
+ return h;
}
rb_hash_aset(h, key, RSTRUCT_GET(s, i));
}