Skip to content

Commit 4587960

Browse files
authored
Stricter Allocation Test (#34)
thx for making everything a little stricter @weissi
1 parent f1d37cd commit 4587960

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
- $GITHUB_WORKSPACE:/src
7474
options: --workdir /src
7575
env:
76-
MAX_ALLOCS_ALLOWED_jsonvalue_to_bytes: 1000
76+
MAX_ALLOCS_ALLOWED_jsonvalue_to_bytes: 0
7777
steps:
7878
- name: Checkout
7979
uses: actions/checkout@v1
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import PureSwiftJSONParsing
22

33
func run(identifier: String) {
4-
let sampleString = SampleStructure.sampleJSON
5-
let sampleBytes = [UInt8](sampleString.utf8)
6-
let sampleJSON = try! JSONParser().parse(bytes: sampleBytes)
7-
8-
measure(identifier: identifier) {
9-
for _ in 0..<1_000 {
10-
var bytes = [UInt8]() // <-- this is the only real allocation
11-
bytes.reserveCapacity(6000) // <-- reserve capactity so high we don't need reallocs
12-
sampleJSON.appendBytes(to: &bytes)
13-
}
14-
15-
return 1_000
4+
let sampleString = SampleStructure.sampleJSON
5+
let sampleBytes = [UInt8](sampleString.utf8)
6+
let sampleJSON = try! JSONParser().parse(bytes: sampleBytes)
7+
8+
var bytes = [UInt8]() // <-- this is the only real allocation
9+
bytes.reserveCapacity(6000) // <-- reserve capactity so high we don't need reallocs
10+
11+
measure(identifier: identifier) {
12+
for _ in 0..<1_000 {
13+
bytes.removeAll(keepingCapacity: true)
14+
sampleJSON.appendBytes(to: &bytes)
1615
}
16+
17+
return 1_000
18+
}
1719
}

0 commit comments

Comments
 (0)