-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathStringMemoryTest.swift
64 lines (51 loc) · 1.38 KB
/
StringMemoryTest.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -O %s -o %t/StringMemoryTest
// RUN: %target-codesign %t/StringMemoryTest
// RUN: %target-run %t/StringMemoryTest | %FileCheck %s
// REQUIRES: optimized_stdlib
// REQUIRES: executable_test
// REQUIRES: objc_interop
import Foundation
let str = "abcdefg\u{A758}hijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\u{A759}"
let str2 = "abcdefg\u{A759}hijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\u{A758}"
@inline(never)
func lookup(_ str: String, _ dict: [String: Int]) -> Bool {
if let _ = dict[str] {
return true
}
return false
}
@inline(never)
func uppercase(_ str: String) -> String {
return str.uppercased()
}
@inline(never)
func lowercase(_ str: String) -> String {
return str.lowercased()
}
/// Make sure the hash function does not leak.
let dict = [ "foo" : 1]
for _ in 0 ..< 10_000_000 {
if lookup("\u{1F1E7}\u{1F1E7}", dict) {
print("Found?!")
}
if uppercase(str) == "A" {
print("Found?!")
}
if lowercase(str2) == "A" {
print("Found?!")
}
}
// CHECK-NOT: Found?!
// CHECK: Not found
print("Not found")
var usage = rusage()
getrusage(RUSAGE_SELF, &usage)
// CHECK: success
// CHECK-NOT: failure
// We should not need 50MB for this.
if usage.ru_maxrss > 50 * 1024 * 1024 {
print("failure - should not need 50MB!")
} else {
print("success")
}