Skip to content

Commit

Permalink
Merge pull request #168 from RSBat/main
Browse files Browse the repository at this point in the history
Make faster duplicate keys checking
  • Loading branch information
charleskorn authored Aug 12, 2021
2 parents 7d9e96f + 4498347 commit 8fcf0eb
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 8fcf0eb

Please sign in to comment.