[5.8] [stdlib] Fix String.reserveCapacity underallocation (#65988)
* [stdlib] Fix String.reserveCapacity underallocation (#65902)
When called on a string that is not uniquely referenced,
`String.reserveCapacity(_:)` ignores the current capacity, using
the passed-in capacity for the size of its new storage. This can
result in an underallocation and write past the end of the new
buffer.
This fix changes the new size calculation to use the current UTF-8
count as the minimum. Non-native or non-unique strings
now allocate the requested capacity (or space enough for the
current contents, if that's larger than what's requested).
rdar://109275875
Fixes #53483
* Fix String capacity growth tests for watchOS
watchOS devices can have different allocation characteristics
from other devices. This modifies the string capacity growth
tests to be more flexible about measuring the growth in
capacity, specifically when more is allocated than requested.