@@ -480,6 +480,9 @@ def imports_string
480480 end
481481
482482 class RubyMethod
483+ # How many arguments we can invoke without needing to box arguments
484+ MAX_UNBOXED_ARITY_LENGTH = 3
485+
483486 def initialize ( ruby_class , name , java_signature = nil , annotations = [ ] )
484487 @ruby_class = ruby_class
485488 @name = name
@@ -495,6 +498,10 @@ def constructor?
495498 false
496499 end
497500
501+ def arity
502+ typed_args . size
503+ end
504+
498505 def to_s
499506 declarator_string do
500507 <<-JAVA
@@ -519,7 +526,13 @@ def annotations_string
519526 end
520527
521528 def conversion_string ( var_names )
522- var_names . map { |a | " IRubyObject ruby_#{ a } = JavaUtil.convertJavaToRuby(__ruby__, #{ a } );" } . join ( "\n " )
529+ if arity <= MAX_UNBOXED_ARITY_LENGTH
530+ var_names . map { |a | " IRubyObject ruby_#{ a } = JavaUtil.convertJavaToRuby(__ruby__, #{ a } );" } . join ( "\n " )
531+ else
532+ str = " IRubyObject ruby_args[] = new IRubyObject[#{ arity } ];\n "
533+ var_names . each_with_index { |a , i | str += " ruby_args[#{ i } ] = JavaUtil.convertJavaToRuby(__ruby__, #{ a } );\n " }
534+ str
535+ end
523536 end
524537
525538 # FIXME: We should allow all valid modifiers
@@ -574,8 +587,12 @@ def var_names
574587 def passed_args
575588 return @passed_args if @passed_args
576589
577- @passed_args = var_names . map { |a | "ruby_#{ a } " } . join ( ', ' )
578- @passed_args = ', ' + @passed_args if args . size > 0
590+ if arity <= MAX_UNBOXED_ARITY_LENGTH
591+ @passed_args = var_names . map { |a | "ruby_#{ a } " } . join ( ', ' )
592+ @passed_args = ', ' + @passed_args if args . size > 0
593+ else
594+ @passed_args = ", ruby_args" ;
595+ end
579596 end
580597
581598 def return_type
0 commit comments