Przeglądaj źródła

template functions should not be simplified (#498)

Maggie Nolan 5 lat temu
rodzic
commit
73b556cfc1
No account linked to committer's email address
2 zmienionych plików z 9 dodań i 3 usunięć
  1. 5
    3
      internal/graph/graph.go
  2. 4
    0
      internal/graph/graph_test.go

+ 5
- 3
internal/graph/graph.go Wyświetl plik

@@ -28,9 +28,10 @@ import (
28 28
 )
29 29
 
30 30
 var (
31
-	javaRegExp = regexp.MustCompile(`^(?:[a-z]\w*\.)*([A-Z][\w\$]*\.(?:<init>|[a-z][\w\$]*(?:\$\d+)?))(?:(?:\()|$)`)
32
-	goRegExp   = regexp.MustCompile(`^(?:[\w\-\.]+\/)+(.+)`)
33
-	cppRegExp  = regexp.MustCompile(`^(?:(?:\(anonymous namespace\)::)(\w+$))|(?:(?:\(anonymous namespace\)::)?(?:[_a-zA-Z]\w*\::|)*(_*[A-Z]\w*::~?[_a-zA-Z]\w*))`)
31
+	javaRegExp               = regexp.MustCompile(`^(?:[a-z]\w*\.)*([A-Z][\w\$]*\.(?:<init>|[a-z][\w\$]*(?:\$\d+)?))(?:(?:\()|$)`)
32
+	goRegExp                 = regexp.MustCompile(`^(?:[\w\-\.]+\/)+(.+)`)
33
+	cppRegExp                = regexp.MustCompile(`^(?:[_a-zA-Z]\w*::)+(_*[A-Z]\w*::~?[_a-zA-Z]\w*)`)
34
+	cppAnonymousPrefixRegExp = regexp.MustCompile(`^\(anonymous namespace\)::`)
34 35
 )
35 36
 
36 37
 // Graph summarizes a performance profile into a format that is
@@ -429,6 +430,7 @@ func newTree(prof *profile.Profile, o *Options) (g *Graph) {
429 430
 
430 431
 // ShortenFunctionName returns a shortened version of a function's name.
431 432
 func ShortenFunctionName(f string) string {
433
+	f = cppAnonymousPrefixRegExp.ReplaceAllString(f, "")
432 434
 	for _, re := range []*regexp.Regexp{goRegExp, javaRegExp, cppRegExp} {
433 435
 		if matches := re.FindStringSubmatch(f); len(matches) >= 2 {
434 436
 			return strings.Join(matches[1:], "")

+ 4
- 0
internal/graph/graph_test.go Wyświetl plik

@@ -475,6 +475,10 @@ func TestShortenFunctionName(t *testing.T) {
475 475
 			"foo_bar::Foo::bar",
476 476
 			"Foo::bar",
477 477
 		},
478
+		{
479
+			"Foo::bar::baz<float, long, int>::operator()",
480
+			"Foo::bar::baz<float, long, int>::operator()",
481
+		},
478 482
 		{
479 483
 			"foo",
480 484
 			"foo",