File tree Expand file tree Collapse file tree 3 files changed +14
-27
lines changed
core/commonMain/src/kotlinx/serialization Expand file tree Collapse file tree 3 files changed +14
-27
lines changed Original file line number Diff line number Diff line change @@ -562,19 +562,12 @@ public interface CompositeDecoder {
562
562
*/
563
563
public inline fun <T > Decoder.decodeStructure (
564
564
descriptor : SerialDescriptor ,
565
- block : CompositeDecoder .() -> T
565
+ crossinline block : CompositeDecoder .() -> T
566
566
): T {
567
567
val composite = beginStructure(descriptor)
568
- var ex: Throwable ? = null
569
- try {
570
- return composite.block()
571
- } catch (e: Throwable ) {
572
- ex = e
573
- throw e
574
- } finally {
575
- // End structure only if there is no exception, otherwise it can be swallowed
576
- if (ex == null ) composite.endStructure(descriptor)
577
- }
568
+ val result = composite.block()
569
+ composite.endStructure(descriptor)
570
+ return result
578
571
}
579
572
580
573
private const val decodeMethodDeprecated = " Please migrate to decodeElement method which accepts old value." +
Original file line number Diff line number Diff line change @@ -473,18 +473,13 @@ public interface CompositeEncoder {
473
473
/* *
474
474
* Begins a structure, encodes it using the given [block] and ends it.
475
475
*/
476
- public inline fun Encoder.encodeStructure (descriptor : SerialDescriptor , block : CompositeEncoder .() -> Unit ) {
476
+ public inline fun Encoder.encodeStructure (
477
+ descriptor : SerialDescriptor ,
478
+ crossinline block : CompositeEncoder .() -> Unit
479
+ ) {
477
480
val composite = beginStructure(descriptor)
478
- var ex: Throwable ? = null
479
- try {
480
- composite.block()
481
- } catch (e: Throwable ) {
482
- ex = e
483
- throw e
484
- } finally {
485
- // End structure only if there is no exception, otherwise it can be swallowed
486
- if (ex == null ) composite.endStructure(descriptor)
487
- }
481
+ composite.block()
482
+ composite.endStructure(descriptor)
488
483
}
489
484
490
485
/* *
@@ -495,10 +490,9 @@ public inline fun Encoder.encodeCollection(
495
490
collectionSize : Int ,
496
491
crossinline block : CompositeEncoder .() -> Unit
497
492
) {
498
- with (beginCollection(descriptor, collectionSize)) {
499
- block()
500
- endStructure(descriptor)
501
- }
493
+ val composite = beginCollection(descriptor, collectionSize)
494
+ composite.block()
495
+ composite.endStructure(descriptor)
502
496
}
503
497
504
498
/* *
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ public abstract class AbstractPolymorphicSerializer<T : Any> internal constructo
40
40
var klassName: String? = null
41
41
var value: Any? = null
42
42
if (decodeSequentially()) {
43
- return decodeSequentially(this )
43
+ return @decodeStructure decodeSequentially(this )
44
44
}
45
45
46
46
mainLoop@ while (true ) {
You can’t perform that action at this time.
0 commit comments