Uploaded image for project: 'Swift'
  1. Swift
  2. SR-6243

_fastEnumerationStorageMutationsPtr isn't doing anything

    XMLWordPrintable

    Details

      Description

      In the standard library's Shims.swift, there are these declarations:

      /// A dummy value to be used as the target for `mutationsPtr` in fast
      /// enumeration implementations.
      internal var _fastEnumerationStorageMutationsTarget: CUnsignedLong = 0
      
      /// A dummy pointer to be used as `mutationsPtr` in fast enumeration
      /// implementations.
      public // SPI(Foundation)
      var _fastEnumerationStorageMutationsPtr: UnsafeMutablePointer<CUnsignedLong> {
        return UnsafeMutablePointer(
            Builtin.addressof(&_fastEnumerationStorageMutationsTarget))
      }
      

      There's no reason to expose this publicly. The way NSFastEnumeration works, the mutationsPtr either points to a word-sized chunk of memory that will change if the collection is mutated (to catch mutation-while-iterating bugs), or it points to some constant memory. That means the standard library and the Foundation overlay can each use the address of their own global variable if they don't want to bother checking for mutations, and they don't need a wrapper function to do it.

        Attachments

          Activity

            People

            Assignee:
            mox Mox Soini
            Reporter:
            jrose Jordan Rose
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: