Skip to content

Instantly share code, notes, and snippets.

@lrytz
Created November 20, 2015 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lrytz/2eb3e398b866fc83e894 to your computer and use it in GitHub Desktop.
Save lrytz/2eb3e398b866fc83e894 to your computer and use it in GitHub Desktop.
class C {
  @inline final def m8[T, U, V](f: (T, U) => V, x: T, y: U) = f(x, y)
  def t8 = {
    val fun = (x: Int, y: Double) => 1l + x + y.toLong
    m8(fun, 1, 2d)
  }
}

compiles to

public class C {
  public final m8(Lscala/Function2;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    ALOAD 1
    ALOAD 2
    ALOAD 3
    INVOKEINTERFACE scala/Function2.apply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    ARETURN

  public t8()J
    ICONST_1
    LDC 2.0
    INVOKESTATIC C.C$$$anonfun$1 (ID)J
    LRETURN

  public final static synthetic C$$$anonfun$1(ID)J
    LCONST_1
    ILOAD 0
    I2L
    LADD
    DLOAD 1
    D2L
    LADD
    LRETURN

All boxing / unboxing in t8 is eliminated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment