| 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 Function |
| 9 |
func (fn Function) Equal(val Function) bool { |
| 10 |
return fn.NameStrindex() == val.NameStrindex() && |
| 11 |
fn.SystemNameStrindex() == val.SystemNameStrindex() && |
| 12 |
fn.FilenameStrindex() == val.FilenameStrindex() && |
| 13 |
fn.StartLine() == val.StartLine() |
| 14 |
} |
| 15 |
|
| 16 |
// switchDictionary updates the Function, switching its indices from one |
| 17 |
// dictionary to another. |
| 18 |
func (fn Function) switchDictionary(src, dst ProfilesDictionary) error { |
| 19 |
if fn.NameStrindex() > 0 { |
| 20 |
if src.StringTable().Len() < int(fn.NameStrindex()) { |
| 21 |
return fmt.Errorf("invalid name index %d", fn.NameStrindex()) |
| 22 |
} |
| 23 |
|
| 24 |
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(fn.NameStrindex()))) |
| 25 |
if err != nil { |
| 26 |
return fmt.Errorf("couldn't set name: %w", err) |
| 27 |
} |
| 28 |
fn.SetNameStrindex(idx) |
| 29 |
} |
| 30 |
|
| 31 |
if fn.SystemNameStrindex() > 0 { |
| 32 |
if src.StringTable().Len() < int(fn.SystemNameStrindex()) { |
| 33 |
return fmt.Errorf("invalid system name index %d", fn.SystemNameStrindex()) |
| 34 |
} |
| 35 |
|
| 36 |
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(fn.SystemNameStrindex()))) |
| 37 |
if err != nil { |
| 38 |
return fmt.Errorf("couldn't set system name: %w", err) |
| 39 |
} |
| 40 |
fn.SetSystemNameStrindex(idx) |
| 41 |
} |
| 42 |
|
| 43 |
if fn.FilenameStrindex() > 0 { |
| 44 |
if src.StringTable().Len() < int(fn.FilenameStrindex()) { |
| 45 |
return fmt.Errorf("invalid filename index %d", fn.FilenameStrindex()) |
| 46 |
} |
| 47 |
|
| 48 |
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(fn.FilenameStrindex()))) |
| 49 |
if err != nil { |
| 50 |
return fmt.Errorf("couldn't set filename: %w", err) |
| 51 |
} |
| 52 |
fn.SetFilenameStrindex(idx) |
| 53 |
} |
| 54 |
|
| 55 |
return nil |
| 56 |
} |