Skip to content

Commit 705756f

Browse files
authored
avoid extra allocation in collections mappers (#309)
1 parent 7fe7b56 commit 705756f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

mappie-api/src/commonMain/kotlin/tech/mappie/api/builtin/collections/ListMappers.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ public class IterableToListMapper<FROM, TO>(private val inner: Mappie1<FROM, TO>
77
: ObjectMappie<Iterable<FROM>, List<TO>>() {
88

99
override fun map(from: Iterable<FROM>): List<TO> =
10-
from.map(inner::map).toList()
10+
from.mapTo(mutableListOf(), inner::map)
1111
}
1212

1313
public class IterableToMutableListMapper<FROM, TO>(private val inner: Mappie1<FROM, TO>)
1414
: ObjectMappie<Iterable<FROM>, MutableList<TO>>() {
1515

1616
override fun map(from: Iterable<FROM>): MutableList<TO> =
17-
from.map(inner::map).toMutableList()
17+
from.mapTo(mutableListOf(), inner::map)
1818
}

mappie-api/src/commonMain/kotlin/tech/mappie/api/builtin/collections/SetMappers.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public class IterableToSetMapper<FROM, TO>(private val inner: Mappie1<FROM, TO>
88
: ObjectMappie<Iterable<FROM>, Set<TO>>() {
99

1010
override fun map(from: Iterable<FROM>): Set<TO> =
11-
from.map( inner::map).toSet()
11+
from.mapTo(mutableSetOf(), inner::map)
1212
}
1313

1414
public class IterableToMutableSetMapper<FROM, TO>(private val inner: Mappie1<FROM, TO> = generated())
1515
: ObjectMappie<Iterable<FROM>, MutableSet<TO>>() {
1616

1717
override fun map(from: Iterable<FROM>): MutableSet<TO> =
18-
from.map( inner::map).toMutableSet()
18+
from.mapTo(mutableSetOf(), inner::map)
1919
}

0 commit comments

Comments
 (0)