From 5232bd6e5bd23a9e095acf02713dba89a03cf142 Mon Sep 17 00:00:00 2001 From: Manik Rana Date: Tue, 9 Jul 2024 23:37:46 +0530 Subject: [PATCH] feat: document deepcopyparser Co-authored-by: Arthur Silva Sens Signed-off-by: Manik Rana --- model/textparse/openmetricsparse.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/model/textparse/openmetricsparse.go b/model/textparse/openmetricsparse.go index 2c4cecb7c4d3..56bd4dec9b56 100644 --- a/model/textparse/openmetricsparse.go +++ b/model/textparse/openmetricsparse.go @@ -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)