Skip to content

Commit

Permalink
feat: document deepcopyparser
Browse files Browse the repository at this point in the history
Co-authored-by: Arthur Silva Sens <[email protected]>
Signed-off-by: Manik Rana <[email protected]>
  • Loading branch information
Maniktherana and ArthurSens authored Jul 9, 2024
1 parent f72d4e6 commit 5232bd6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions model/textparse/openmetricsparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,10 @@ loop:
return nil
}

// We need this because we want offsets of the original parser unchanged when
// we're working with a new parser in CreatedTimeStamp().
// deepCopyParser creates a copy of a parser without re-using the slices' original memory addresses.
// The function `CreatedTimestamp()` uses a copy of the parser to "peek" at _created lines that might be several lines ahead, without changing the state of the original parser.
//
// Additionally, deepCopyParser switches `skipCT` from false to true, because this new parser needs to return _created lines.
func deepCopyParser(p *OpenMetricsParser) OpenMetricsParser {
newB := make([]byte, len(p.l.b))
copy(newB, p.l.b)
Expand Down

0 comments on commit 5232bd6

Please sign in to comment.