JS: remove -XtypedArraysEnabled flag (always true now)
This commit is contained in:
committed by
Anton Bannykh
parent
60aae55233
commit
4a5e9bbc7f
+5
-13
@@ -200,13 +200,7 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
if (isArray(type)) {
|
||||
if (ArrayFIF.typedArraysEnabled(context().getConfig())) {
|
||||
return namer().isArray();
|
||||
}
|
||||
else {
|
||||
return Namer.IS_ARRAY_FUN_REF;
|
||||
}
|
||||
|
||||
return namer().isArray();
|
||||
}
|
||||
|
||||
if (TypePredicatesKt.getCHAR_SEQUENCE().test(type)) return namer().isCharSequence();
|
||||
@@ -244,12 +238,10 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
return namer().isTypeOf(new JsStringLiteral("number"));
|
||||
}
|
||||
|
||||
if (ArrayFIF.typedArraysEnabled(context().getConfig())) {
|
||||
if (KotlinBuiltIns.isPrimitiveArray(type)) {
|
||||
PrimitiveType arrayType = KotlinBuiltIns.getPrimitiveArrayElementType(type);
|
||||
assert arrayType != null;
|
||||
return namer().isPrimitiveArray(arrayType);
|
||||
}
|
||||
if (KotlinBuiltIns.isPrimitiveArray(type)) {
|
||||
PrimitiveType arrayType = KotlinBuiltIns.getPrimitiveArrayElementType(type);
|
||||
assert arrayType != null;
|
||||
return namer().isPrimitiveArray(arrayType);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
+20
-58
@@ -61,16 +61,12 @@ object ArrayFIF : CompositeFIF() {
|
||||
@JvmField
|
||||
val LENGTH_PROPERTY_INTRINSIC = BuiltInPropertyIntrinsic("length")
|
||||
|
||||
@JvmStatic
|
||||
fun typedArraysEnabled(config: JsConfig) = config.configuration.get(JSConfigurationKeys.TYPED_ARRAYS_ENABLED, true)
|
||||
|
||||
fun castOrCreatePrimitiveArray(ctx: TranslationContext, type: PrimitiveType?, arg: JsArrayLiteral): JsExpression {
|
||||
if (type == null || !typedArraysEnabled(ctx.config)) return arg
|
||||
if (type == null) return arg
|
||||
|
||||
return if (type in TYPED_ARRAY_MAP) {
|
||||
createTypedArray(type, arg)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
JsAstUtils.invokeKotlinFunction(type.lowerCaseName + "ArrayOf", *arg.expressions.toTypedArray())
|
||||
}
|
||||
}
|
||||
@@ -100,21 +96,10 @@ object ArrayFIF : CompositeFIF() {
|
||||
if (functionParam.type.getValueParameterTypesFromFunctionType().size != 1) return null
|
||||
|
||||
val primitiveType = KotlinBuiltIns.getPrimitiveArrayElementType(constructedClass.defaultType)
|
||||
return if (typedArraysEnabled(config) && primitiveType != null) {
|
||||
if (primitiveType in TYPED_ARRAY_MAP) {
|
||||
"kotlin.fillArray"
|
||||
}
|
||||
else {
|
||||
"kotlin.${primitiveType.lowerCaseName}ArrayF"
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (primitiveType == CHAR) {
|
||||
"kotlin.untypedCharArrayF"
|
||||
}
|
||||
else {
|
||||
"kotlin.newArrayF"
|
||||
}
|
||||
return when {
|
||||
primitiveType in TYPED_ARRAY_MAP -> "kotlin.fillArray"
|
||||
primitiveType != null -> "kotlin.${primitiveType.lowerCaseName}ArrayF"
|
||||
else -> "kotlin.newArrayF"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,23 +118,11 @@ object ArrayFIF : CompositeFIF() {
|
||||
add(pattern(NamePredicate(type.arrayTypeName), "<init>(Int)"), intrinsify { _, arguments, context ->
|
||||
assert(arguments.size == 1) { "Array <init>(Int) expression must have one argument." }
|
||||
val (size) = arguments
|
||||
if (type in TYPED_ARRAY_MAP) {
|
||||
createTypedArray(type, size)
|
||||
} else {
|
||||
JsAstUtils.invokeKotlinFunction("${type.lowerCaseName}Array", size)
|
||||
|
||||
if (typedArraysEnabled(context.config)) {
|
||||
if (type in TYPED_ARRAY_MAP) {
|
||||
createTypedArray(type, size)
|
||||
}
|
||||
else {
|
||||
JsAstUtils.invokeKotlinFunction("${type.lowerCaseName}Array", size)
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
val initValue = when (type) {
|
||||
BOOLEAN -> JsBooleanLiteral(false)
|
||||
LONG -> JsNameRef(Namer.LONG_ZERO, Namer.kotlinLong())
|
||||
else -> JsIntLiteral(0)
|
||||
}
|
||||
JsAstUtils.invokeKotlinFunction("newArray", size, initValue)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -157,12 +130,7 @@ object ArrayFIF : CompositeFIF() {
|
||||
|
||||
add(pattern(NamePredicate(type.arrayTypeName), "iterator"), intrinsify { callInfo, _, context ->
|
||||
val receiver = callInfo.dispatchReceiver
|
||||
if (typedArraysEnabled(context.config)) {
|
||||
JsAstUtils.invokeKotlinFunction("${type.lowerCaseName}ArrayIterator", receiver!!)
|
||||
}
|
||||
else {
|
||||
JsAstUtils.invokeKotlinFunction("arrayIterator", receiver!!, JsStringLiteral(type.arrayTypeName.asString()))
|
||||
}
|
||||
JsAstUtils.invokeKotlinFunction("${type.lowerCaseName}ArrayIterator", receiver!!)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -180,16 +148,10 @@ object ArrayFIF : CompositeFIF() {
|
||||
return intrinsify { callInfo, arguments, context ->
|
||||
assert(arguments.size == 2) { "Array <init>(Int,Function1) expression must have two arguments." }
|
||||
val (size, fn) = arguments
|
||||
val invocation = if (typedArraysEnabled(context.config) && type != null) {
|
||||
if (type in TYPED_ARRAY_MAP) {
|
||||
JsAstUtils.invokeKotlinFunction("fillArray", createTypedArray(type, size), fn)
|
||||
}
|
||||
else {
|
||||
JsAstUtils.invokeKotlinFunction("${type.lowerCaseName}ArrayF", size, fn)
|
||||
}
|
||||
}
|
||||
else {
|
||||
JsAstUtils.invokeKotlinFunction(if (type == CHAR) "untypedCharArrayF" else "newArrayF", size, fn)
|
||||
val invocation = when {
|
||||
type in TYPED_ARRAY_MAP -> JsAstUtils.invokeKotlinFunction("fillArray", createTypedArray(type!!, size), fn)
|
||||
type != null -> JsAstUtils.invokeKotlinFunction("${type.lowerCaseName}ArrayF", size, fn)
|
||||
else -> JsAstUtils.invokeKotlinFunction("newArrayF", size, fn)
|
||||
}
|
||||
invocation.inlineStrategy = InlineStrategy.IN_PLACE
|
||||
val descriptor = callInfo.resolvedCall.resultingDescriptor.original
|
||||
@@ -203,10 +165,10 @@ object ArrayFIF : CompositeFIF() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun intrinsify(f: (callInfo: CallInfo, arguments: List<JsExpression>, context: TranslationContext) -> JsExpression)
|
||||
= object : FunctionIntrinsic() {
|
||||
override fun apply(callInfo: CallInfo, arguments: List<JsExpression>, context: TranslationContext): JsExpression {
|
||||
return f(callInfo, arguments, context)
|
||||
private fun intrinsify(f: (callInfo: CallInfo, arguments: List<JsExpression>, context: TranslationContext) -> JsExpression) =
|
||||
object : FunctionIntrinsic() {
|
||||
override fun apply(callInfo: CallInfo, arguments: List<JsExpression>, context: TranslationContext): JsExpression {
|
||||
return f(callInfo, arguments, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user