Skip to content

Commit 3029608

Browse files
authored
Update EnvironmentHelper API (#122)
1 parent 04dede6 commit 3029608

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

Sources/OpenSwiftUI/App/AppGraph.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class AppGraph: GraphHost {
2525
}
2626

2727
private lazy var launchProfileOptions = LaunchProfileOptions(
28-
rawValue: EnvironmentHelper.value(for: "OPENSWIFTUI_PROFILE_LAUNCH")
28+
rawValue: EnvironmentHelper.int32(for: "OPENSWIFTUI_PROFILE_LAUNCH")
2929
)
3030

3131
var didCollectLaunchProfile: Bool = false

Sources/OpenSwiftUI/Core/Graph/GraphHost.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
internal import COpenSwiftUI
1010
internal import OpenGraphShims
1111

12-
private let waitingForPreviewThunks = EnvironmentHelper.value(for: "XCODE_RUNNING_FOR_PREVIEWS") != 0
12+
private let waitingForPreviewThunks = EnvironmentHelper.bool(for: "XCODE_RUNNING_FOR_PREVIEWS")
1313
private var blockedGraphHosts: [Unmanaged<GraphHost>] = []
1414

1515
class GraphHost {

Sources/OpenSwiftUI/Test/_BenchmarkHost.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Foundation
1212
import QuartzCore
1313
#endif
1414

15-
private let enableProfiler = EnvironmentHelper.value(for: "OPENSWIFTUI_PROFILE_BENCHMARKS") != 0
15+
private let enableProfiler = EnvironmentHelper.bool(for: "OPENSWIFTUI_PROFILE_BENCHMARKS")
1616

1717
public protocol _BenchmarkHost: AnyObject {
1818
func _renderForTest(interval: Double)

Sources/OpenSwiftUI/View/Debug/TODO/ViewDebug.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extension _ViewDebug {
6969
@inline(__always)
7070
static func instantiateIfNeeded() {
7171
if !isInitialized {
72-
let debugValue = UInt32(bitPattern: EnvironmentHelper.value(for: "OPENSWIFTUI_VIEW_DEBUG"))
72+
let debugValue = UInt32(bitPattern: EnvironmentHelper.int32(for: "OPENSWIFTUI_VIEW_DEBUG"))
7373
properties = Properties(rawValue: debugValue)
7474
isInitialized = true
7575
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
//
2+
// EnvironmentHelper.swift
3+
// OpenSwiftUICore
4+
//
5+
// Audited for RELEASE_2024
6+
// Status: Complete
7+
18
#if canImport(Darwin)
29
import Darwin
310
#elseif canImport(Glibc)
@@ -8,15 +15,19 @@ import WASILibc
815
#error("Unsupported Platform")
916
#endif
1017

11-
enum EnvironmentHelper {
18+
package enum EnvironmentHelper {
1219
@_transparent
13-
@inline(__always)
14-
static func value(for key: String) -> Int32 {
20+
package static func int32(for key: String) -> Int32 {
1521
key.withCString { string in
1622
guard let env = getenv(string) else {
1723
return 0
1824
}
1925
return atoi(env)
20-
}
26+
}
27+
}
28+
29+
@_transparent
30+
package static func bool(for key: String) -> Bool {
31+
int32(for: key) != 0
2132
}
2233
}

0 commit comments

Comments
 (0)