groostav
02/07/2019, 8:40 PMsealed inline class Token{}
object UnixNewline: Token()
object WindowsNewline: Token()
inline class Character(val impl: Char): Token()
it would make one of my tokenizers run a whole lot fasterserebit
02/07/2019, 8:42 PMgroostav
02/07/2019, 8:42 PMserebit
02/07/2019, 8:43 PMgroostav
02/07/2019, 8:43 PMinline class
as a type in a when
expression with exhaustive coverageserebit
02/07/2019, 8:44 PMToken
, it requires a value of that type, there’s nothing to inline theregroostav
02/07/2019, 8:47 PMinterface Whatever{}
inline class MyImpl(val char: impl): Whatever
fun myFunc(p1: Whatever){
serebit
02/07/2019, 8:48 PMWhatever
can’t be inlined, and if i’m not mistaken, a function accepting Whatever
has to accept a boxed (i.e. MyImpl
) value rather than an impl
groostav
02/07/2019, 8:52 PMWhatever
, but if your point is that boxing is going to cause me to see those object allocations regardless then I'm stuck. Presumably if I express my tokenizer as a set of static functions and/or inline functions, then the object allocations go away?Andreas Sinz
02/07/2019, 8:55 PMWhatever
, auto-boxing is involvedgroostav
02/07/2019, 8:58 PMinterface Whatever {}
inline class Impl(val value: Char)
inline fun Whatever.doSomething() = when(this) {
is Whatever -> value
else -> '0'
}
fun something(){
val x: Impl = Impl('1')
val y = x.doSomething()
}
is going to involve allocating a boxed ImplAsWhatever
?serebit
02/07/2019, 9:06 PMWhatever.doSomething()
might have to cast to Whatever
, meaning yes(?)groostav
02/07/2019, 9:09 PMWhatever
for example?).inline class
concept.serebit
02/07/2019, 9:12 PMdoSomething
groostav
02/07/2019, 9:12 PMserebit
02/07/2019, 9:12 PMsomething
compiles down to this:
public static final void something() {
char x = Impl.constructor-impl('1');
Whatever $receiver$iv = Impl.box-impl(x);
int $i$f$doSomething = false;
if ($receiver$iv instanceof Whatever) {
$receiver$iv.getValue();
} else {
boolean var10000 = true;
}
}
groostav
02/07/2019, 9:19 PMserebit
02/07/2019, 9:19 PM