mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
use rb_hash_new_with_size()
* hash.c: use rb_hash_new_with_size(). * marshal.c: ditto * struct.c: ditto * vm_args.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
cb0f3183cb
commit
8875e0ca4a
4 changed files with 7 additions and 7 deletions
2
hash.c
2
hash.c
|
|
@ -2426,7 +2426,7 @@ rb_hash_invert_i(VALUE key, VALUE value, VALUE hash)
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_hash_invert(VALUE hash)
|
rb_hash_invert(VALUE hash)
|
||||||
{
|
{
|
||||||
VALUE h = rb_hash_new();
|
VALUE h = rb_hash_new_with_size(RHASH_SIZE(hash));
|
||||||
|
|
||||||
rb_hash_foreach(hash, rb_hash_invert_i, h);
|
rb_hash_foreach(hash, rb_hash_invert_i, h);
|
||||||
return h;
|
return h;
|
||||||
|
|
|
||||||
|
|
@ -1772,7 +1772,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
|
||||||
{
|
{
|
||||||
long len = r_long(arg);
|
long len = r_long(arg);
|
||||||
|
|
||||||
v = rb_hash_new();
|
v = rb_hash_new_with_size(len);
|
||||||
v = r_entry(v, arg);
|
v = r_entry(v, arg);
|
||||||
arg->readable += (len - 1) * 2;
|
arg->readable += (len - 1) * 2;
|
||||||
while (len--) {
|
while (len--) {
|
||||||
|
|
|
||||||
2
struct.c
2
struct.c
|
|
@ -794,7 +794,7 @@ rb_struct_to_a(VALUE s)
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_struct_to_h(VALUE s)
|
rb_struct_to_h(VALUE s)
|
||||||
{
|
{
|
||||||
VALUE h = rb_hash_new();
|
VALUE h = rb_hash_new_with_size(RSTRUCT_LEN(s));
|
||||||
VALUE members = rb_struct_members(s);
|
VALUE members = rb_struct_members(s);
|
||||||
long i;
|
long i;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,7 @@ args_kw_argv_to_hash(struct args_info *args)
|
||||||
const struct rb_call_info_kw_arg *kw_arg = args->kw_arg;
|
const struct rb_call_info_kw_arg *kw_arg = args->kw_arg;
|
||||||
const VALUE *const passed_keywords = kw_arg->keywords;
|
const VALUE *const passed_keywords = kw_arg->keywords;
|
||||||
const int kw_len = kw_arg->keyword_len;
|
const int kw_len = kw_arg->keyword_len;
|
||||||
VALUE h = rb_hash_new();
|
VALUE h = rb_hash_new_with_size(kw_len);
|
||||||
const int kw_start = args->argc - kw_len;
|
const int kw_start = args->argc - kw_len;
|
||||||
const VALUE * const kw_argv = args->argv + kw_start;
|
const VALUE * const kw_argv = args->argv + kw_start;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -257,11 +257,11 @@ args_kw_argv_to_hash(struct args_info *args)
|
||||||
static void
|
static void
|
||||||
args_stored_kw_argv_to_hash(struct args_info *args)
|
args_stored_kw_argv_to_hash(struct args_info *args)
|
||||||
{
|
{
|
||||||
VALUE h = rb_hash_new();
|
|
||||||
int i;
|
int i;
|
||||||
const struct rb_call_info_kw_arg *kw_arg = args->kw_arg;
|
const struct rb_call_info_kw_arg *kw_arg = args->kw_arg;
|
||||||
const VALUE *const passed_keywords = kw_arg->keywords;
|
const VALUE *const passed_keywords = kw_arg->keywords;
|
||||||
const int passed_keyword_len = kw_arg->keyword_len;
|
const int passed_keyword_len = kw_arg->keyword_len;
|
||||||
|
VALUE h = rb_hash_new_with_size(passed_keyword_len);
|
||||||
|
|
||||||
for (i=0; i<passed_keyword_len; i++) {
|
for (i=0; i<passed_keyword_len; i++) {
|
||||||
rb_hash_aset(h, passed_keywords[i], args->kw_argv[i]);
|
rb_hash_aset(h, passed_keywords[i], args->kw_argv[i]);
|
||||||
|
|
@ -365,7 +365,7 @@ static VALUE
|
||||||
make_rest_kw_hash(const VALUE *passed_keywords, int passed_keyword_len, const VALUE *kw_argv)
|
make_rest_kw_hash(const VALUE *passed_keywords, int passed_keyword_len, const VALUE *kw_argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
VALUE obj = rb_hash_new();
|
VALUE obj = rb_hash_new_with_size(passed_keyword_len);
|
||||||
|
|
||||||
for (i=0; i<passed_keyword_len; i++) {
|
for (i=0; i<passed_keyword_len; i++) {
|
||||||
if (kw_argv[i] != Qundef) {
|
if (kw_argv[i] != Qundef) {
|
||||||
|
|
@ -780,7 +780,7 @@ vm_caller_setup_arg_kw(rb_control_frame_t *cfp, struct rb_calling_info *calling,
|
||||||
struct rb_call_info_with_kwarg *ci_kw = (struct rb_call_info_with_kwarg *)ci;
|
struct rb_call_info_with_kwarg *ci_kw = (struct rb_call_info_with_kwarg *)ci;
|
||||||
const VALUE *const passed_keywords = ci_kw->kw_arg->keywords;
|
const VALUE *const passed_keywords = ci_kw->kw_arg->keywords;
|
||||||
const int kw_len = ci_kw->kw_arg->keyword_len;
|
const int kw_len = ci_kw->kw_arg->keyword_len;
|
||||||
const VALUE h = rb_hash_new();
|
const VALUE h = rb_hash_new_with_size(kw_len);
|
||||||
VALUE *sp = cfp->sp;
|
VALUE *sp = cfp->sp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue