@@ -266,9 +266,9 @@ func StripSourceRetentionOptions(image bufimage.Image) (bufimage.Image, error) {
266266type transitiveClosure struct {
267267 // The elements included in the transitive closure.
268268 elements map [namedDescriptor ]closureInclusionMode
269- // The ordered set of imports for each file. This allows for re-writing imports
269+ // The set of imports for each file. This allows for re-writing imports
270270 // for files whose contents have been pruned.
271- imports map [string ]* orderedImports
271+ imports map [string ]map [ string ] struct {}
272272}
273273
274274type closureInclusionMode int
@@ -295,7 +295,7 @@ const (
295295func newTransitiveClosure () * transitiveClosure {
296296 return & transitiveClosure {
297297 elements : map [namedDescriptor ]closureInclusionMode {},
298- imports : map [string ]* orderedImports {},
298+ imports : map [string ]map [ string ] struct {} {},
299299 }
300300}
301301
@@ -414,10 +414,10 @@ func (t *transitiveClosure) addImport(fromPath, toPath string) {
414414 }
415415 imps := t .imports [fromPath ]
416416 if imps == nil {
417- imps = newOrderedImports ( )
417+ imps = make ( map [ string ] struct {}, 2 )
418418 t .imports [fromPath ] = imps
419419 }
420- imps . add ( toPath )
420+ imps [ toPath ] = struct {}{}
421421}
422422
423423func (t * transitiveClosure ) addElement (
@@ -1066,60 +1066,3 @@ func stripSourceRetentionOptionsFromFile(imageFile bufimage.ImageFile) (bufimage
10661066 imageFile .UnusedDependencyIndexes (),
10671067 )
10681068}
1069-
1070- // orderedImports is a structure to maintain an ordered set of imports. This is needed
1071- // because we want to be able to iterate through imports in a deterministic way when filtering
1072- // the image.
1073- type orderedImports struct {
1074- pathToIndex map [string ]int
1075- paths []string
1076- }
1077-
1078- // newOrderedImports creates a new orderedImports structure.
1079- func newOrderedImports () * orderedImports {
1080- return & orderedImports {
1081- pathToIndex : map [string ]int {},
1082- }
1083- }
1084-
1085- // index returns the index for a given path. If the path does not exist in index map, -1
1086- // is returned and should be considered deleted.
1087- func (o * orderedImports ) index (path string ) int {
1088- if index , ok := o .pathToIndex [path ]; ok {
1089- return index
1090- }
1091- return - 1
1092- }
1093-
1094- // add appends a path to the paths list and the index in the map. If a key already exists,
1095- // then this is a no-op.
1096- func (o * orderedImports ) add (path string ) {
1097- if _ , ok := o .pathToIndex [path ]; ! ok {
1098- o .pathToIndex [path ] = len (o .paths )
1099- o .paths = append (o .paths , path )
1100- }
1101- }
1102-
1103- // delete removes a key from the index map of ordered imports. If a non-existent path is
1104- // set for deletion, then this is a no-op.
1105- // Note that the path is not removed from the paths list. If you want to iterate through
1106- // the paths, use keys() to get all non-deleted keys.
1107- func (o * orderedImports ) delete (path string ) {
1108- delete (o .pathToIndex , path )
1109- }
1110-
1111- // keys provides all non-deleted keys from the ordered imports.
1112- func (o * orderedImports ) keys () []string {
1113- keys := make ([]string , 0 , len (o .pathToIndex ))
1114- for _ , path := range o .paths {
1115- if _ , ok := o .pathToIndex [path ]; ok {
1116- keys = append (keys , path )
1117- }
1118- }
1119- return keys
1120- }
1121-
1122- // len returns the number of paths in the ordered imports.
1123- func (o * orderedImports ) len () int {
1124- return len (o .pathToIndex )
1125- }
0 commit comments