i have a “path” type that has a builder API that looks like
extension Path
{
@inlinable public static
func / (prefix:Self, last:String) -> Self
{
var prefix:Self = prefix
prefix.append(last)
return prefix
}
}
(hopefully the layout of Path
should be obvious, but it is essentially a wrapper around a [String]
array.) but apparently prefix
lives for the entire duration of a function call, so /
has linear complexity even if it is being used like:
let path:Path = "first" / "second" / "third" / "fourth"
which makes the whole thing quadratic in number of path components.
what is the best way to get this to actually work like an array literal? (i am not using array literal syntax because we cannot statically assert the array literal has at least one path component.)