Skip to content

Commit

Permalink
Update EnvironmentHelper API (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye authored Sep 24, 2024
1 parent 04dede6 commit 3029608
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/App/AppGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class AppGraph: GraphHost {
}

private lazy var launchProfileOptions = LaunchProfileOptions(
rawValue: EnvironmentHelper.value(for: "OPENSWIFTUI_PROFILE_LAUNCH")
rawValue: EnvironmentHelper.int32(for: "OPENSWIFTUI_PROFILE_LAUNCH")
)

var didCollectLaunchProfile: Bool = false
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Core/Graph/GraphHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
internal import COpenSwiftUI
internal import OpenGraphShims

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

class GraphHost {
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Test/_BenchmarkHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
import QuartzCore
#endif

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

public protocol _BenchmarkHost: AnyObject {
func _renderForTest(interval: Double)
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/View/Debug/TODO/ViewDebug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extension _ViewDebug {
@inline(__always)
static func instantiateIfNeeded() {
if !isInitialized {
let debugValue = UInt32(bitPattern: EnvironmentHelper.value(for: "OPENSWIFTUI_VIEW_DEBUG"))
let debugValue = UInt32(bitPattern: EnvironmentHelper.int32(for: "OPENSWIFTUI_VIEW_DEBUG"))
properties = Properties(rawValue: debugValue)
isInitialized = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// EnvironmentHelper.swift
// OpenSwiftUICore
//
// Audited for RELEASE_2024
// Status: Complete

#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
Expand All @@ -8,15 +15,19 @@ import WASILibc
#error("Unsupported Platform")
#endif

enum EnvironmentHelper {
package enum EnvironmentHelper {
@_transparent
@inline(__always)
static func value(for key: String) -> Int32 {
package static func int32(for key: String) -> Int32 {
key.withCString { string in
guard let env = getenv(string) else {
return 0
}
return atoi(env)
}
}
}

@_transparent
package static func bool(for key: String) -> Bool {
int32(for: key) != 0
}
}

0 comments on commit 3029608

Please sign in to comment.