feat: document deepcopyparser

Co-authored-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Manik Rana <Manikrana54@gmail.com>
Signed-off-by: Manik Rana <manikrana54@gmail.com>
This commit is contained in:
Manik Rana 2024-07-09 23:37:46 +05:30 committed by Manik Rana
parent 9c4bc807be
commit e9391dd61f

View file

@ -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)