Skip to content

Commit

Permalink
Optimise the Swift version of Vexilla Client (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joannis committed Mar 17, 2024
1 parent cf101eb commit 01db167
Show file tree
Hide file tree
Showing 10 changed files with 314 additions and 741 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -229,7 +229,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: |
cd ./clients/swift
swift build
swift test
env:
Expand Down
6 changes: 4 additions & 2 deletions clients/swift/Package.swift → Package.swift
Expand Up @@ -21,11 +21,13 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "VexillaClient",
dependencies: []
dependencies: [],
path: "clients/swift/Sources/VexillaClient"
),
.testTarget(
name: "VexillaClientTests",
dependencies: ["VexillaClient"]
dependencies: ["VexillaClient"],
path: "clients/swift/Tests/VexillaClientTests"
),
]
)
5 changes: 1 addition & 4 deletions clients/swift/.vscode/extensions.json
@@ -1,8 +1,5 @@
{
"recommendations": [
"DEVSENSE.composer-php-vscode",
"DEVSENSE.intelli-php-vscode",
"DEVSENSE.phptools-vscode",
"DEVSENSE.profiler-php-vscode"
"sswg.swift-lang"
]
}
7 changes: 3 additions & 4 deletions clients/swift/Sources/VexillaClient/Hashing.swift
@@ -1,10 +1,9 @@
import Foundation

func hashString(stringToHash: String, seed: Float64) -> Float64 {
let chars = Array(stringToHash)

let total = chars.reduce(0) { a, b in
a + Int(b.asciiValue ?? 0)
var total = 0
for char in stringToHash.utf8 {
total += Int(char)
}

var calculated = Float64(total) * seed * 42.0
Expand Down
6 changes: 3 additions & 3 deletions clients/swift/Sources/VexillaClient/Scheduling.swift
Expand Up @@ -12,7 +12,7 @@ func isScheduleActiveWithNow(schedule: Schedule, scheduleType: ScheduleType, now
let nowSeconds = now.timeIntervalSince1970
var calendar = Calendar(identifier: Calendar.Identifier.iso8601)
guard let utc = TimeZone(identifier: "UTC") else {
throw "Could not create UTC calendar"
throw VexillaSchedulingError.couldNotCreateUTCTimezone
}
calendar.timeZone = utc

Expand All @@ -26,11 +26,11 @@ func isScheduleActiveWithNow(schedule: Schedule, scheduleType: ScheduleType, now

let endDate = Date(timeIntervalSince1970: TimeInterval(schedule.end / 1000))
guard let dayAfterEndDate = calendar.date(byAdding: .day, value: 1, to: endDate) else {
throw "could not add day to endDate"
throw VexillaSchedulingError.couldNotAddDayToEndDate
}
let endOfEndDate = calendar.startOfDay(for: dayAfterEndDate)

if startOfStartDate > now || endOfEndDate < now {
guard startOfStartDate <= now && endOfEndDate >= now else {
return false
}

Expand Down

0 comments on commit 01db167

Please sign in to comment.