func maxSharedPrefix()

in models/v3/msgs/subject.go [46:63]


func maxSharedPrefix(a, b []*arm.ResourceID) (results []*arm.ResourceID) {
	// We can find the maximal arm.ResourceID which is a shared prefix of a and b by walking the slices backwards comparing their scopes.
	// While the scopes match, we append the scope to results.  By definition, a[len(a)-1] and b[len(b)-1] match.  Note that a and b may
	// have a significant shared prefix without having the same length.

	for i := 1; len(a)-i >= 0 && len(b)-i >= 0; i++ {
		// We compare using String() because unfortunately isChild is unexported.  At least String() caches its result internally.
		if a[len(a)-i].String() == b[len(b)-i].String() {
			results = append(results, a[len(a)-i])
		} else {
			break
		}
	}

	slices.Reverse(results)

	return results
}