From 3b43b391b5b9a2bf86f14aa8d4b34d37fbbbd0d1 Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Wed, 17 Jul 2024 12:49:37 -0400 Subject: [PATCH] Add some comments and remove leftover WIP noise. --- Sources/System/FilePath/FilePath.swift | 14 +++++--------- Sources/System/SystemString.swift | 5 +++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Sources/System/FilePath/FilePath.swift b/Sources/System/FilePath/FilePath.swift index 1b9dfc2..67752c0 100644 --- a/Sources/System/FilePath/FilePath.swift +++ b/Sources/System/FilePath/FilePath.swift @@ -59,15 +59,6 @@ public struct FilePath: Sendable { } } -/* - extension FilePath: Hashable, Codable { - - - precondition(_hasRoot == (self.root != nil)) - } - } - */ - @available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *) extension FilePath { /// The length of the file path, excluding the null terminator. @@ -76,6 +67,11 @@ extension FilePath { @available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *) extension FilePath: Hashable, Codable { + // Encoder is synthesized; it probably should have been explicit and used + // a single-value container, but making that change now is somewhat risky. + + // Decoder is written explicitly to ensure that we validate invariants on + // untrusted input. public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self._storage = try container.decode(SystemString.self, forKey: ._storage) diff --git a/Sources/System/SystemString.swift b/Sources/System/SystemString.swift index ab70334..57abc62 100644 --- a/Sources/System/SystemString.swift +++ b/Sources/System/SystemString.swift @@ -174,6 +174,11 @@ extension SystemString: RangeReplaceableCollection { } extension SystemString: Hashable, Codable { + // Encoder is synthesized; it probably should have been explicit and used + // a single-value container, but making that change now is somewhat risky. + + // Decoder is written explicitly to ensure that we validate invariants on + // untrusted input. public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.nullTerminatedStorage = try container.decode(