Skip to content

Commit

Permalink
Fix merging for maplikeSerializer when the map is not empty (by using…
Browse files Browse the repository at this point in the history
… the actual size * 2). (#1712)

The index in the conceptual array is twice the amount of elements in the list. This way the
reading is consistent between single and multipass. Also decoders can thus use even/odd to
determine whether to read the key or value.
  • Loading branch information
pdvrieze committed Oct 14, 2021
1 parent bb0d274 commit 85be8a7
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -257,7 +257,7 @@ internal class LinkedHashMapSerializer<K, V>(
override fun Map<K, V>.collectionSize(): Int = size
override fun Map<K, V>.collectionIterator(): Iterator<Map.Entry<K, V>> = iterator()
override fun builder(): LinkedHashMap<K, V> = LinkedHashMap()
override fun LinkedHashMap<K, V>.builderSize(): Int = size
override fun LinkedHashMap<K, V>.builderSize(): Int = size * 2
override fun LinkedHashMap<K, V>.toResult(): Map<K, V> = this
override fun Map<K, V>.toBuilder(): LinkedHashMap<K, V> = this as? LinkedHashMap<K, V> ?: LinkedHashMap(this)
override fun LinkedHashMap<K, V>.checkCapacity(size: Int) {}
Expand All @@ -273,7 +273,7 @@ internal class HashMapSerializer<K, V>(
override fun Map<K, V>.collectionSize(): Int = size
override fun Map<K, V>.collectionIterator(): Iterator<Map.Entry<K, V>> = iterator()
override fun builder(): HashMap<K, V> = HashMap()
override fun HashMap<K, V>.builderSize(): Int = size
override fun HashMap<K, V>.builderSize(): Int = size * 2
override fun HashMap<K, V>.toResult(): Map<K, V> = this
override fun Map<K, V>.toBuilder(): HashMap<K, V> = this as? HashMap<K, V> ?: HashMap(this)
override fun HashMap<K, V>.checkCapacity(size: Int) {}
Expand Down

0 comments on commit 85be8a7

Please sign in to comment.