Skip to content

Commit

Permalink
Remove lastElem
Browse files Browse the repository at this point in the history
  • Loading branch information
apstndb committed Oct 15, 2024
1 parent 42ae05e commit e1a3e81
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ast/pos.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *CTE) End() token.Pos { return c.Rparen + 1 }
func (s *Select) Pos() token.Pos { return s.Select }

func (s *Select) End() token.Pos {
return firstValidEnd(s.Limit, s.OrderBy, s.Having, s.GroupBy, s.Where, s.From, lastElem(s.Results))
return firstValidEnd(s.Limit, s.OrderBy, s.Having, s.GroupBy, s.Where, s.From, s.Results[len(s.Results)-1])
}

func (c *CompoundQuery) Pos() token.Pos {
Expand Down
8 changes: 1 addition & 7 deletions ast/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ func sqlJoin[T Node](elems []T, sep string) string {

// Helper functions for Pos(), End()

// lastElem returns last element of slice s.
// This function corresponds to NodeSliceVar[$] in ast.go.
func lastElem[T any](s []T) T {
return s[len(s)-1]
}

// firstValidEnd returns the first valid Pos() in argument.
// "valid" means the node is not nil and Pos().Invalid() is not true.
// This function corresponds to "(n0 ?? n1 ?? ...).End()"
Expand Down Expand Up @@ -87,5 +81,5 @@ func lastEnd[T Node](s []T) token.Pos {
if len(s) == 0 {
return token.InvalidPos
}
return lastElem(s).End()
return s[len(s)-1].End()
}

0 comments on commit e1a3e81

Please sign in to comment.