Files
swift-mirror/test/stdlib/StringMemoryTest.swift
Arnold Schwaighofer ec5f40f12f runtime: Move String implementation stubs that want need the auto-released return value optimization to an ARC compiled file
String's hashValue function is implemented in terms of Foundation's hash
function in a runtime function on darwin platforms. For non-ASCII strings we
will call str.decomposedStringWithCanonicalMapping inside this runtime function
which will allocate a new NSString and return the result in the current
autorelease pool. We implemented this function in a file compiled without ARC.
This meant that we would leak said NSString into the current active autorelease
pool.
This patch moves the implementation to a file compiled with ARC. ARC will insert
objc_retainAutoreleasedReturnValue call and on platforms that require it an
marker for the hand-off of the autoreleased return value optimization.

SR-4889
rdar://32199117
2017-10-06 11:12:22 -07:00

43 lines
840 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift -O %s -o %t/StringMemoryTest
// RUN: %target-run %t/StringMemoryTest | %FileCheck %s
// REQUIRES: optimized_stdlib
// REQUIRES: executable_test
// REQUIRES: objc_interop
import Foundation
@inline(never)
func lookup(_ str: String, _ dict: [String: Int]) -> Bool {
if let _ = dict[str] {
return true
}
return false
}
/// 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?!")
}
}
// 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")
}