From 8cd798431d80fd5f2363a715e04b3c57cfcf4815 Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Wed, 14 Nov 2018 17:42:19 -0800 Subject: [PATCH] [Swift] Change getStateToAltMap to use Int as the dictionary key, not ATNState. The ATNState hashValue and == override are just using the stateNumber field, so using the Int directly is equivalent, and saves bouncing through those methods. This also seems to be a correctness issue with the new Hashable protocol changes in Swift 4.2 (though I admit that I don't know why). Remove PredictionMode.getStateToAltMap, which was just a stub onto ATNConfigSet.getStateToAltMap and didn't seem to be doing anything useful. --- .../Swift/Sources/Antlr4/atn/ATNConfigSet.swift | 8 ++++---- .../Swift/Sources/Antlr4/atn/PredictionMode.swift | 14 +------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift b/runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift index 66e650237..15254b350 100644 --- a/runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift +++ b/runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift @@ -321,17 +321,17 @@ public class ATNConfigSet: Hashable, CustomStringConvertible { return Array(configToAlts.values) } - public final func getStateToAltMap() -> [ATNState: BitSet] { + public func getStateToAltMap() -> [Int: BitSet] { let length = configs.count - var m = [ATNState: BitSet]() + var m = [Int: BitSet]() for i in 0.. [ATNState: BitSet] { - return configs.getStateToAltMap() - } - public static func hasStateAssociatedWithOneAlt(_ configs: ATNConfigSet) -> Bool { - let x = getStateToAltMap(configs) + let x = configs.getStateToAltMap() for alts in x.values { if alts.cardinality() == 1 { return true