Merge "Fold annotations." am: b3f3e7b3f7 am: e27ecb85d4

Original change: https://android-review.googlesource.com/c/platform/build/+/1944765

Change-Id: I596d2bfe32bbb85091f39b2a11068e27734ed9ad
diff --git a/tools/compliance/policy/policy.go b/tools/compliance/policy/policy.go
index 9dab05b..d3e412b 100644
--- a/tools/compliance/policy/policy.go
+++ b/tools/compliance/policy/policy.go
@@ -20,6 +20,15 @@
 )
 
 var (
+	// RecognizedAnnotations identifies the set of annotations that have
+	// meaning for compliance policy.
+	RecognizedAnnotations = map[string]string{
+		// used in readgraph.go to avoid creating 1000's of copies of the below 3 strings.
+		"static":    "static",
+		"dynamic":   "dynamic",
+		"toolchain": "toolchain",
+	}
+
 	// ImpliesUnencumbered lists the condition names representing an author attempt to disclaim copyright.
 	ImpliesUnencumbered = ConditionNames{"unencumbered"}
 
diff --git a/tools/compliance/readgraph.go b/tools/compliance/readgraph.go
index 45fa134..face775 100644
--- a/tools/compliance/readgraph.go
+++ b/tools/compliance/readgraph.go
@@ -188,10 +188,11 @@
 		}
 		annotations := newEdgeAnnotations()
 		for _, a := range ad.Annotations {
-			if len(a) == 0 {
-				continue
+			// look up a common constant annotation string from a small map
+			// instead of creating 1000's of copies of the same 3 strings.
+			if ann, ok := RecognizedAnnotations[a]; ok {
+				annotations.annotations[ann] = true
 			}
-			annotations.annotations[a] = true
 		}
 		*edges = append(*edges, &dependencyEdge{target, dependency, annotations})
 	}