Source file src/cmd/vendor/github.com/google/pprof/internal/report/shortnames.go
1 // Copyright 2022 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package report 16 17 import ( 18 "regexp" 19 20 "github.com/google/pprof/internal/graph" 21 ) 22 23 var sepRE = regexp.MustCompile(`::|\.`) 24 25 // shortNameList returns a non-empty sequence of shortened names 26 // (in decreasing preference) that can be used to represent name. 27 func shortNameList(name string) []string { 28 name = graph.ShortenFunctionName(name) 29 seps := sepRE.FindAllStringIndex(name, -1) 30 result := make([]string, 0, len(seps)+1) 31 result = append(result, name) 32 for _, sep := range seps { 33 // Suffix starting just after sep 34 if sep[1] < len(name) { 35 result = append(result, name[sep[1]:]) 36 } 37 } 38 return result 39 } 40