mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Use super trampolines to let us override several more NSString methods (-UTF8String, -cStringUsingEncoding:, and -getCString:maxLength:encoding:) for performance
This commit is contained in:
@@ -686,6 +686,18 @@ NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remain
|
||||
|
||||
NSStringAPIs.test("getCString(_:maxLength:encoding:)") {
|
||||
let s = "abc あかさた"
|
||||
do {
|
||||
// A significantly too small buffer
|
||||
let bufferLength = 1
|
||||
var buffer = Array(
|
||||
repeating: CChar(bitPattern: 0xff), count: bufferLength)
|
||||
let result = s.getCString(&buffer, maxLength: 100,
|
||||
encoding: .utf8)
|
||||
expectFalse(result)
|
||||
let result2 = s.getCString(&buffer, maxLength: 1,
|
||||
encoding: .utf8)
|
||||
expectFalse(result2)
|
||||
}
|
||||
do {
|
||||
// The largest buffer that cannot accommodate the string plus null terminator.
|
||||
let bufferLength = 16
|
||||
@@ -694,6 +706,9 @@ NSStringAPIs.test("getCString(_:maxLength:encoding:)") {
|
||||
let result = s.getCString(&buffer, maxLength: 100,
|
||||
encoding: .utf8)
|
||||
expectFalse(result)
|
||||
let result2 = s.getCString(&buffer, maxLength: 16,
|
||||
encoding: .utf8)
|
||||
expectFalse(result2)
|
||||
}
|
||||
do {
|
||||
// The smallest buffer where the result can fit.
|
||||
@@ -708,6 +723,10 @@ NSStringAPIs.test("getCString(_:maxLength:encoding:)") {
|
||||
encoding: .utf8)
|
||||
expectTrue(result)
|
||||
expectEqualSequence(expectedStr, buffer)
|
||||
let result2 = s.getCString(&buffer, maxLength: 17,
|
||||
encoding: .utf8)
|
||||
expectTrue(result2)
|
||||
expectEqualSequence(expectedStr, buffer)
|
||||
}
|
||||
do {
|
||||
// Limit buffer size with 'maxLength'.
|
||||
|
||||
Reference in New Issue
Block a user