-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert public API lists to arrays #1395
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import app.cash.redwood.tooling.schema.ProtocolWidget | |
import app.cash.redwood.tooling.schema.ProtocolWidget.ProtocolChildren | ||
import app.cash.redwood.tooling.schema.ProtocolWidget.ProtocolEvent | ||
import app.cash.redwood.tooling.schema.ProtocolWidget.ProtocolProperty | ||
import com.squareup.kotlinpoet.ARRAY | ||
import com.squareup.kotlinpoet.AnnotationSpec | ||
import com.squareup.kotlinpoet.BOOLEAN | ||
import com.squareup.kotlinpoet.BYTE | ||
|
@@ -704,14 +705,15 @@ internal fun generateComposeProtocolModifierSerialization( | |
.addModifiers(INTERNAL) | ||
.receiver(Redwood.Modifier) | ||
.addParameter("json", KotlinxSerialization.Json) | ||
.returns(LIST.parameterizedBy(Protocol.ModifierElement)) | ||
.returns(ARRAY.parameterizedBy(Protocol.ModifierElement)) | ||
.beginControlFlow("return %M", Stdlib.buildList) | ||
.addStatement( | ||
"this@%L.forEach { element -> add(element.%M(json)) }", | ||
name, | ||
schema.modifierToProtocol, | ||
) | ||
.endControlFlow() | ||
.addCode("⇥.toTypedArray()⇤") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not convinced that just adding this actually helps perf since it's still building a list first. But I think to build an array directly, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We control |
||
.build(), | ||
) | ||
.addFunction( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah this is unfortunate. I initially envisioned that we would be able to do this with a property-local serializer. But I guess that's too late because the enclosing serializer for the type is what determines whether or not the value needs to be included. Once we're inside a serializer for the property we are always going to write out the value.
I'll look into this more. Maybe ask the serialization folks if they'd be open to a similar annotation to treat arrays as values and not references.
Another potential option in the future is to use a
value class
when customequals
gets supported. Then we could have aValueBasedArray
wrapper around an array. This assumes that it doesn't somehow incur boxing, which is not yet clear since there's no implementation of this to play with yet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that appears to be the case.
I filed Kotlin/kotlinx.serialization#2409, let's see what they think.