| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile" |
| 5 |
|
| 6 |
import "fmt" |
| 7 |
|
| 8 |
// Equal checks equality with another LineSlice |
| 9 |
func (l LineSlice) Equal(val LineSlice) bool { |
| 10 |
if l.Len() != val.Len() { |
| 11 |
return false |
| 12 |
} |
| 13 |
|
| 14 |
for i := range l.Len() { |
| 15 |
if !l.At(i).Equal(val.At(i)) { |
| 16 |
return false |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
return true |
| 21 |
} |
| 22 |
|
| 23 |
// Equal checks equality with another Line |
| 24 |
func (l Line) Equal(val Line) bool { |
| 25 |
return l.Column() == val.Column() && |
| 26 |
l.FunctionIndex() == val.FunctionIndex() && |
| 27 |
l.Line() == val.Line() |
| 28 |
} |
| 29 |
|
| 30 |
// switchDictionary updates the Line, switching its indices from one |
| 31 |
// dictionary to another. |
| 32 |
func (l Line) switchDictionary(src, dst ProfilesDictionary) error { |
| 33 |
if l.FunctionIndex() > 0 { |
| 34 |
if src.FunctionTable().Len() < int(l.FunctionIndex()) { |
| 35 |
return fmt.Errorf("invalid function index %d", l.FunctionIndex()) |
| 36 |
} |
| 37 |
|
| 38 |
fn := src.FunctionTable().At(int(l.FunctionIndex())) |
| 39 |
err := fn.switchDictionary(src, dst) |
| 40 |
if err != nil { |
| 41 |
return fmt.Errorf("couldn't switch function dictionary: %w", err) |
| 42 |
} |
| 43 |
|
| 44 |
idx, err := SetFunction(dst.FunctionTable(), fn) |
| 45 |
if err != nil { |
| 46 |
return fmt.Errorf("couldn't set function: %w", err) |
| 47 |
} |
| 48 |
l.SetFunctionIndex(idx) |
| 49 |
} |
| 50 |
|
| 51 |
return nil |
| 52 |
} |