Skip to content

Commit

Permalink
golang: Add to quick checks to PredictionContext Equals checks (they …
Browse files Browse the repository at this point in the history
…are in use

in other runtimes):

1. If pointers are equal it's the same object
2. If we are comparing singletons both types must be singletons

Signed-off-by: Eytan Heidingsfeld <32422402+ehmm@users.noreply.github.com>
  • Loading branch information
ehmm authored and parrt committed Apr 2, 2024
1 parent 2244af3 commit 6628b00
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion runtime/Go/antlr/v4/prediction_context.go
Expand Up @@ -115,6 +115,9 @@ func (p *PredictionContext) Hash() int {
}

func (p *PredictionContext) Equals(other Collectable[*PredictionContext]) bool {
if p == other {
return true
}
switch p.pcType {
case PredictionContextEmpty:
otherP := other.(*PredictionContext)
Expand Down Expand Up @@ -152,7 +155,7 @@ func (p *PredictionContext) SingletonEquals(other Collectable[*PredictionContext
return false
}
otherP := other.(*PredictionContext)
if otherP == nil {
if otherP == nil || otherP.pcType != PredictionContextSingleton {
return false
}

Expand Down

0 comments on commit 6628b00

Please sign in to comment.