mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Revert "vm_eval.c: add rb_yield_assoc_or_values()"
This reverts commit r60095 to prevent performance degradation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									8148b7013c
								
							
						
					
					
						commit
						f5740d18bf
					
				
					 4 changed files with 53 additions and 23 deletions
				
			
		
							
								
								
									
										46
									
								
								hash.c
									
										
									
									
									
								
							
							
						
						
									
										46
									
								
								hash.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1775,7 +1775,17 @@ rb_hash_each_key(VALUE hash)
 | 
			
		|||
static int
 | 
			
		||||
each_pair_i(VALUE key, VALUE value)
 | 
			
		||||
{
 | 
			
		||||
    rb_yield_assoc_or_values(key, value);
 | 
			
		||||
    rb_yield(rb_assoc_new(key, value));
 | 
			
		||||
    return ST_CONTINUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
each_pair_i_fast(VALUE key, VALUE value)
 | 
			
		||||
{
 | 
			
		||||
    VALUE argv[2];
 | 
			
		||||
    argv[0] = key;
 | 
			
		||||
    argv[1] = value;
 | 
			
		||||
    rb_yield_values2(2, argv);
 | 
			
		||||
    return ST_CONTINUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1805,7 +1815,10 @@ static VALUE
 | 
			
		|||
rb_hash_each_pair(VALUE hash)
 | 
			
		||||
{
 | 
			
		||||
    RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
 | 
			
		||||
    rb_hash_foreach(hash, each_pair_i, 0);
 | 
			
		||||
    if (rb_block_arity() > 1)
 | 
			
		||||
	rb_hash_foreach(hash, each_pair_i_fast, 0);
 | 
			
		||||
    else
 | 
			
		||||
	rb_hash_foreach(hash, each_pair_i, 0);
 | 
			
		||||
    return hash;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2896,7 +2909,18 @@ rb_init_identtable_with_size(st_index_t size)
 | 
			
		|||
static int
 | 
			
		||||
any_p_i(VALUE key, VALUE value, VALUE arg)
 | 
			
		||||
{
 | 
			
		||||
    VALUE ret = rb_yield_assoc_or_values(key, value);
 | 
			
		||||
    VALUE ret = rb_yield(rb_assoc_new(key, value));
 | 
			
		||||
    if (RTEST(ret)) {
 | 
			
		||||
	*(VALUE *)arg = Qtrue;
 | 
			
		||||
	return ST_STOP;
 | 
			
		||||
    }
 | 
			
		||||
    return ST_CONTINUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
any_p_i_fast(VALUE key, VALUE value, VALUE arg)
 | 
			
		||||
{
 | 
			
		||||
    VALUE ret = rb_yield_values(2, key, value);
 | 
			
		||||
    if (RTEST(ret)) {
 | 
			
		||||
	*(VALUE *)arg = Qtrue;
 | 
			
		||||
	return ST_STOP;
 | 
			
		||||
| 
						 | 
				
			
			@ -2921,7 +2945,10 @@ rb_hash_any_p(VALUE hash)
 | 
			
		|||
	/* yields pairs, never false */
 | 
			
		||||
	return Qtrue;
 | 
			
		||||
    }
 | 
			
		||||
    rb_hash_foreach(hash, any_p_i, (VALUE)&ret);
 | 
			
		||||
    if (rb_block_arity() > 1)
 | 
			
		||||
	rb_hash_foreach(hash, any_p_i_fast, (VALUE)&ret);
 | 
			
		||||
    else
 | 
			
		||||
	rb_hash_foreach(hash, any_p_i, (VALUE)&ret);
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3767,8 +3794,15 @@ env_each_pair(VALUE ehash)
 | 
			
		|||
    }
 | 
			
		||||
    FREE_ENVIRON(environ);
 | 
			
		||||
 | 
			
		||||
    for (i=0; i<RARRAY_LEN(ary); i+=2) {
 | 
			
		||||
	rb_yield_assoc_or_values(RARRAY_AREF(ary, i), RARRAY_AREF(ary, i+1));
 | 
			
		||||
    if (rb_block_arity() > 1) {
 | 
			
		||||
	for (i=0; i<RARRAY_LEN(ary); i+=2) {
 | 
			
		||||
	    rb_yield_values(2, RARRAY_AREF(ary, i), RARRAY_AREF(ary, i+1));
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
	for (i=0; i<RARRAY_LEN(ary); i+=2) {
 | 
			
		||||
	    rb_yield(rb_assoc_new(RARRAY_AREF(ary, i), RARRAY_AREF(ary, i+1)));
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
    return ehash;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1768,7 +1768,6 @@ VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv
 | 
			
		|||
VALUE rb_check_funcall_default(VALUE, ID, int, const VALUE *, VALUE);
 | 
			
		||||
VALUE rb_yield_1(VALUE val);
 | 
			
		||||
VALUE rb_yield_force_blockarg(VALUE values);
 | 
			
		||||
VALUE rb_yield_assoc_or_values(VALUE key, VALUE value);
 | 
			
		||||
VALUE rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv,
 | 
			
		||||
		     rb_block_call_func_t bl_proc, int min_argc, int max_argc,
 | 
			
		||||
		     VALUE data2);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										17
									
								
								struct.c
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								struct.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -686,10 +686,19 @@ rb_struct_each_pair(VALUE s)
 | 
			
		|||
 | 
			
		||||
    RETURN_SIZED_ENUMERATOR(s, 0, 0, struct_enum_size);
 | 
			
		||||
    members = rb_struct_members(s);
 | 
			
		||||
    for (i=0; i<RSTRUCT_LEN(s); i++) {
 | 
			
		||||
	VALUE key = rb_ary_entry(members, i);
 | 
			
		||||
	VALUE value = RSTRUCT_GET(s, i);
 | 
			
		||||
	rb_yield_assoc_or_values(key, value);
 | 
			
		||||
    if (rb_block_arity() > 1) {
 | 
			
		||||
	for (i=0; i<RSTRUCT_LEN(s); i++) {
 | 
			
		||||
	    VALUE key = rb_ary_entry(members, i);
 | 
			
		||||
	    VALUE value = RSTRUCT_GET(s, i);
 | 
			
		||||
	    rb_yield_values(2, key, value);
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
	for (i=0; i<RSTRUCT_LEN(s); i++) {
 | 
			
		||||
	    VALUE key = rb_ary_entry(members, i);
 | 
			
		||||
	    VALUE value = RSTRUCT_GET(s, i);
 | 
			
		||||
	    rb_yield(rb_assoc_new(key, value));
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										12
									
								
								vm_eval.c
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								vm_eval.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1009,18 +1009,6 @@ rb_yield_values2(int argc, const VALUE *argv)
 | 
			
		|||
    return rb_yield_0(argc, argv);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
VALUE
 | 
			
		||||
rb_yield_assoc_or_values(VALUE key, VALUE value)
 | 
			
		||||
{
 | 
			
		||||
    if (rb_block_arity() > 1) {
 | 
			
		||||
	VALUE argv[2] = { key, value };
 | 
			
		||||
	return rb_yield_0(2, argv);
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
	return rb_yield_1(rb_assoc_new(key, value));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
VALUE
 | 
			
		||||
rb_yield_splat(VALUE values)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue