nitj: shortcut calls on primitive instances
authorAlexandre Terrasa <alexandre@moz-code.org>
Mon, 6 Jul 2015 16:50:01 +0000 (12:50 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 21 Jul 2015 21:23:21 +0000 (17:23 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/compiler/java_compiler.nit

index 141a6ef..739f210 100644 (file)
@@ -452,6 +452,10 @@ class JavaCompilerVisitor
 
        #  Generate a polymorphic send for `method` with `arguments`
        fun send(mmethod: MMethod, arguments: Array[RuntimeVariable]): nullable RuntimeVariable do
+               # Shortcut calls on primitives
+               if arguments.first.mcasttype.is_java_primitive then
+                       return monomorphic_send(mmethod, arguments.first.mcasttype, arguments)
+               end
                # Polymorphic send
                return table_send(mmethod, arguments)
        end
@@ -562,6 +566,13 @@ class JavaCompilerVisitor
                return res
        end
 
+       # Generate a monomorphic send for the method `m`, the type `t` and the arguments `args`
+       fun monomorphic_send(m: MMethod, t: MType, args: Array[RuntimeVariable]): nullable RuntimeVariable do
+               assert t isa MClassType
+               var propdef = m.lookup_first_definition(self.compiler.mainmodule, t)
+               return self.static_call(propdef, args)
+       end
+
        # Code generation
 
        # Add a line (will be suffixed by `\n`)