Skip to content

Commit 7b0a90d

Browse files
committed
---
yaml --- r: 323056 b: refs/heads/tensorflow-next c: f754d30 h: refs/heads/master
1 parent 8151d5a commit 7b0a90d

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,4 +1461,4 @@ refs/heads/master-rebranch: 86e95c23aa0d37f24ec138b7853146c1cead2e40
14611461
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14621462
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14631463
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec
1464-
refs/heads/tensorflow-next: 9e25fc5421efaeca116247e130a23d23ae3dbcab
1464+
refs/heads/tensorflow-next: f754d30de9fccf1b960f99d4acad9301957ff29d

branches/tensorflow-next/test/stdlib/Inputs/NSSlowString/NSSlowString.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ - (instancetype)initWithString:(NSString *)name {
1818
return self;
1919
}
2020

21+
- (instancetype)initWithCharacters:(const unichar * _Nonnull)chars length:(NSUInteger)count {
22+
NSString *str = [[NSString alloc] initWithCharacters: chars length: count];
23+
self = [self initWithString: str];
24+
return self;
25+
}
26+
2127
- (NSUInteger)length {
2228
return self.stringHolder.length;
2329
}
@@ -34,4 +40,4 @@ - (void *) _fastCharacterContents {
3440
return nil;
3541
}
3642

37-
@end
43+
@end

branches/tensorflow-next/validation-test/stdlib/StringUTF8.swift

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import StdlibUnittest
1616
import StdlibCollectionUnittest
17+
import StdlibUnicodeUnittest
1718

1819
#if _runtime(_ObjC)
1920
import NSSlowString
@@ -49,6 +50,35 @@ var strings: Array<String> = [
4950

5051
let kCFStringEncodingASCII: UInt32 = 0x0600
5152

53+
#if _runtime(_ObjC)
54+
55+
var utf16ByteSequences = utf16Tests.flatMap { $0.value }.map { $0.encoded }
56+
57+
private func testForeignContiguous(slowString: NSSlowString, string: String) {
58+
// Lazily bridged strings are not contiguous UTF-8
59+
var slowString = NSSlowString(string: string) as String
60+
expectFalse(slowString.isFastUTF8)
61+
expectEqualSequence(string.utf8, slowString.utf8)
62+
63+
// They become fast when mutated
64+
slowString.makeNative()
65+
expectTrue(slowString.isFastUTF8)
66+
expectEqualSequence(
67+
string.utf8, slowString.withFastUTF8IfAvailable(Array.init)!)
68+
69+
// Contiguous ASCII CFStrings provide access, even if lazily bridged
70+
if string.isASCII {
71+
let cfString = string.withCString {
72+
CFStringCreateWithCString(nil, $0, kCFStringEncodingASCII)!
73+
} as String
74+
expectTrue(cfString.isFastUTF8)
75+
expectEqualSequence(
76+
string.utf8, cfString.withFastUTF8IfAvailable(Array.init)!)
77+
}
78+
}
79+
80+
#endif
81+
5282
UTF8Tests.test("Contiguous Access") {
5383
for string in strings {
5484
print(string)
@@ -70,28 +100,20 @@ UTF8Tests.test("Contiguous Access") {
70100
// expectTrue(((copy as NSString) as String).isFastUTF8)
71101

72102
#if _runtime(_ObjC)
73-
// Lazily bridged strings are not contiguous UTF-8
74-
var slowString = NSSlowString(string: string) as String
75-
expectFalse(slowString.isFastUTF8)
76-
expectEqualSequence(string.utf8, slowString.utf8)
77-
78-
// They become fast when mutated
79-
slowString.makeNative()
80-
expectTrue(slowString.isFastUTF8)
81-
expectEqualSequence(
82-
string.utf8, slowString.withFastUTF8IfAvailable(Array.init)!)
83-
84-
// Contiguous ASCII CFStrings provide access, even if lazily bridged
85-
if string.isASCII {
86-
let cfString = string.withCString {
87-
CFStringCreateWithCString(nil, $0, kCFStringEncodingASCII)!
88-
} as String
89-
expectTrue(cfString.isFastUTF8)
90-
expectEqualSequence(
91-
string.utf8, cfString.withFastUTF8IfAvailable(Array.init)!)
92-
}
103+
testForeignContiguous(slowString: NSSlowString(string: string),
104+
string: string)
93105
#endif
94106
}
107+
#if _runtime(_ObjC)
108+
for bytes in utf16ByteSequences {
109+
bytes.withContiguousStorageIfAvailable {
110+
let slowString = NSSlowString(characters: $0.baseAddress!,
111+
length: UInt($0.count))
112+
let string = String(decoding: $0, as: UTF16.self)
113+
testForeignContiguous(slowString: slowString, string: string)
114+
}
115+
}
116+
#endif
95117
}
96118

97119
runAllTests()

0 commit comments

Comments
 (0)