From 1f1cc9f8c5ad9bcf2b0b3eadac5a85bc2cdbd0a3 Mon Sep 17 00:00:00 2001 From: Eytan Heidingsfeld <32422402+ehmm@users.noreply.github.com> Date: Mon, 1 Apr 2024 07:20:57 +0000 Subject: [PATCH] golang: Add to quick checks to PredictionContext Equals checks (they 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> --- runtime/Go/antlr/v4/prediction_context.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/Go/antlr/v4/prediction_context.go b/runtime/Go/antlr/v4/prediction_context.go index 7014ac07a9..cd89bd3417 100644 --- a/runtime/Go/antlr/v4/prediction_context.go +++ b/runtime/Go/antlr/v4/prediction_context.go @@ -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) @@ -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 }