This should optimize fine. Using Godbolt.org as an example, you can see that while there is an ARC operation, that retain is on the String
argument, not on the array of entries. As this doesn't +1 the array of entries, it doesn't inherently cause a CoW.
In older versions of Swift the compiler was not so smart, and so we (SwiftNIO) did use exactly this pattern by having a deliberately uninhabited case called _modifying
or similar. This is largely unnecessary now.