Skip to content

Commit

Permalink
Make faster duplicate keys checking
Browse files Browse the repository at this point in the history
  • Loading branch information
tabasavr committed Aug 11, 2021
1 parent 7d9e96f commit 4498347
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/commonMain/kotlin/com/charleskorn/kaml/YamlNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,15 @@ public data class YamlMap(val entries: Map<YamlScalar, YamlNode>, override val p
}
}

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

if (duplicate != null) {
throw DuplicateKeyException(duplicate.path, key.path, key.contentToString())
}

encounteredKeys[key.content] = key
}
}

Expand Down

0 comments on commit 4498347

Please sign in to comment.