[yast-commit] r68054 - in /trunk/ruby-bindings: src/ruby/Y2RubyTypeConv.cc tests/ycp/ruby_from_ycp.ycp

Author: jreidinger Date: Mon Apr 30 16:48:01 2012 New Revision: 68054 URL: http://svn.opensuse.org/viewcvs/yast?rev=68054&view=rev Log: optimalize and simplify hash to map conversion ( use to_a method and fast pointer aritmetic ) Modified: trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc trunk/ruby-bindings/tests/ycp/ruby_from_ycp.ycp Modified: trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyType... ============================================================================== --- trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc (original) +++ trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc Mon Apr 30 16:48:01 2012 @@ -66,13 +66,12 @@ static YCPMap rbhash_2_ycpmap( VALUE value ) { YCPMap map; - VALUE keys = rb_funcall(value, rb_intern("keys"), 0); - int n = NUM2LONG(rb_funcall(keys, rb_intern("size"), 0)); - for ( int i=0; i<n; ++i) + VALUE list = rb_funcall(value, rb_intern("to_a"), 0); //get array of two items array, first is key and second is value + for ( unsigned i=0; i<RARRAY_LEN(list); ++i) { - VALUE rkey = rb_funcall(keys, rb_intern("at"), 1, INT2NUM(i)); - YCPValue ykey = rbvalue_2_ycpvalue(rkey); - YCPValue yvalue = rbvalue_2_ycpvalue( rb_funcall(value, rb_intern("[]"), 1, rkey) ); + VALUE kv_list = *(RARRAY_PTR(list)+i); + YCPValue ykey = rbvalue_2_ycpvalue(*RARRAY_PTR(kv_list)); + YCPValue yvalue = rbvalue_2_ycpvalue(*(RARRAY_PTR(kv_list)+1)); map.add(ykey, yvalue); } return map; Modified: trunk/ruby-bindings/tests/ycp/ruby_from_ycp.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/tests/ycp/ruby_from... ============================================================================== --- trunk/ruby-bindings/tests/ycp/ruby_from_ycp.ycp (original) +++ trunk/ruby-bindings/tests/ycp/ruby_from_ycp.ycp Mon Apr 30 16:48:01 2012 @@ -17,7 +17,8 @@ return false; } map h = tomap(InRuby::get_hash()); - if ( tostring(h["a"]:"") != "b") + y2milestone("get hash: %1",h); + if ( tostring(h["a"]:"") != "b" || tostring(h["b"]:"") != "c" ) { y2error("map is not properly returned: %1",result); return false; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
jreidinger@svn2.opensuse.org