apple / swift-http-types

Version-independent HTTP currency types for Swift
Apache License 2.0
894 stars 47 forks source link

Why does HTTPFields._Storage have a lock? #52

Open Joannis opened 4 months ago

Joannis commented 4 months ago

Since it's handled as CoW through isKnownUniquelyReferenced, I would not expect to need a lock.

guoye-zhang commented 4 months ago

The lock is necessary for the index which is built lazily upon access. It’s possible that multiple immutable fields instances share the same storage without an index, and multiple threads call methods that need the index in parallel.