Skip to content
This repository was archived by the owner on Nov 30, 2025. It is now read-only.

Commit 8fcf0eb

Browse files
authored
Merge pull request #168 from RSBat/main
Make faster duplicate keys checking
2 parents 7d9e96f + 4498347 commit 8fcf0eb

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/commonMain/kotlin/com/charleskorn/kaml/YamlNode.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@ public data class YamlMap(val entries: Map<YamlScalar, YamlNode>, override val p
154154
}
155155
}
156156

157-
keys.forEachIndexed { index, key ->
158-
val duplicate = keys.subList(0, index).firstOrNull { it.equivalentContentTo(key) }
157+
val encounteredKeys = mutableMapOf<String, YamlScalar>()
158+
keys.forEach { key ->
159+
val duplicate = encounteredKeys[key.content]
159160

160161
if (duplicate != null) {
161162
throw DuplicateKeyException(duplicate.path, key.path, key.contentToString())
162163
}
164+
165+
encounteredKeys[key.content] = key
163166
}
164167
}
165168

0 commit comments

Comments
 (0)