Skip to content

Commit b54fb71

Browse files
committed
Refactor lazy-loading for static variables.
Static variables are lazy by default
1 parent 3b4468b commit b54fb71

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

Sources/Utility/Resources.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import POSIX
1818
public final class Resources {
1919
/// The registered path of the main executable.
2020
private static var registeredMainExecutablePath: String? = nil
21-
/// The computed paths for the install path and executable of package manager
22-
static var _computedResourcePaths: (install: String, executable: String?)?
23-
21+
2422
/// Initialize the resources support.
2523
///
2624
/// This function should be called from the module defining the executable
@@ -91,12 +89,10 @@ public final class Resources {
9189
return Path.join(installPath, "lib", "swift", "pm")
9290
}
9391

94-
private static var computedResourcePaths: (install: String, executable: String?) {
95-
if _computedResourcePaths == nil {
96-
_computedResourcePaths = computeResourcesPaths()
97-
}
98-
return _computedResourcePaths!
99-
}
92+
/// The computed paths for the install path and executable of package manager
93+
private static var computedResourcePaths: (install: String, executable: String?) = {
94+
Resources.computeResourcesPaths()
95+
}()
10096

10197
/// Compute the paths for resources.
10298
private static func computeResourcesPaths() -> (install: String, executable: String?) {

0 commit comments

Comments
 (0)