migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.07k stars 70 forks source link

Make StringName and GString Hashable #387

Closed tishin closed 7 months ago

tishin commented 7 months ago

Closes #344, closes #379.

It's probably possible to make it match Swift string hashing:

extension String: Hashable {
  /// Hashes the essential components of this value by feeding them into the
  /// given hasher.
  ///
  /// - Parameter hasher: The hasher to use when combining the components
  ///   of this instance.
  public func hash(into hasher: inout Hasher) {
    if _fastPath(self._guts.isNFCFastUTF8) {
      self._guts.withFastUTF8 {
        hasher.combine(bytes: UnsafeRawBufferPointer($0))
      }
      hasher.combine(0xFF as UInt8) // terminator
    } else {
      _gutsSlice._normalizedHash(into: &hasher)
    }
  }
}

by using toUtf8Buffer, but I don't think there's an effective way to get actual byte array from PackedByteArray.

migueldeicaza commented 7 months ago

Oh this is delightful! Thank you @tishin !