From efbf3af05d61f9a3eaf26452fb9466982299e343 Mon Sep 17 00:00:00 2001 From: schou Date: Tue, 23 Feb 2021 20:46:52 -0500 Subject: [PATCH] reduce addOffst to 2 parameters Signed-off-by: schou --- promql/parser/generated_parser.y | 4 ++-- promql/parser/generated_parser.y.go | 4 ++-- promql/parser/parse.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/promql/parser/generated_parser.y b/promql/parser/generated_parser.y index f80f5f45d..3f914e4ac 100644 --- a/promql/parser/generated_parser.y +++ b/promql/parser/generated_parser.y @@ -383,12 +383,12 @@ paren_expr : LEFT_PAREN expr RIGHT_PAREN offset_expr: expr OFFSET duration { - yylex.(*parser).addOffset($1, $3, 1) + yylex.(*parser).addOffset($1, $3) $$ = $1 } | expr OFFSET SUB duration { - yylex.(*parser).addOffset($1, $4, -1) + yylex.(*parser).addOffset($1, -$4) $$ = $1 } | expr OFFSET error diff --git a/promql/parser/generated_parser.y.go b/promql/parser/generated_parser.y.go index 00f745ec1..e0c5ceac5 100644 --- a/promql/parser/generated_parser.y.go +++ b/promql/parser/generated_parser.y.go @@ -1241,14 +1241,14 @@ yydefault: yyDollar = yyS[yypt-3 : yypt+1] //line generated_parser.y:385 { - yylex.(*parser).addOffset(yyDollar[1].node, yyDollar[3].duration, 1) + yylex.(*parser).addOffset(yyDollar[1].node, yyDollar[3].duration) yyVAL.node = yyDollar[1].node } case 67: yyDollar = yyS[yypt-4 : yypt+1] //line generated_parser.y:390 { - yylex.(*parser).addOffset(yyDollar[1].node, yyDollar[4].duration, -1) + yylex.(*parser).addOffset(yyDollar[1].node, -yyDollar[4].duration) yyVAL.node = yyDollar[1].node } case 68: diff --git a/promql/parser/parse.go b/promql/parser/parse.go index 53db7ebc6..6b81f35f9 100644 --- a/promql/parser/parse.go +++ b/promql/parser/parse.go @@ -683,7 +683,7 @@ func (p *parser) newLabelMatcher(label Item, operator Item, value Item) *labels. } // addOffset is used to set the offset in the generated parser. -func (p *parser) addOffset(e Node, offset time.Duration, direction int) { +func (p *parser) addOffset(e Node, offset time.Duration) { var orgoffsetp *time.Duration var endPosp *Pos @@ -711,7 +711,7 @@ func (p *parser) addOffset(e Node, offset time.Duration, direction int) { if *orgoffsetp != 0 { p.addParseErrf(e.PositionRange(), "offset may not be set multiple times") } else if orgoffsetp != nil { - *orgoffsetp = offset * time.Duration(direction) + *orgoffsetp = offset } *endPosp = p.lastClosing