forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringReallocation.swift
37 lines (31 loc) · 983 Bytes
/
StringReallocation.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
// RUN: %target-run-simple-swift | FileCheck %s
// REQUIRES: executable_test
// CHECK-NOT: Reallocations exceeded 30
func testReallocation() {
var x = "The quick brown fox jumped over the lazy dog\n"._split(" ")
var story = "Let me tell you a story:"
var laps = 1000
var reallocations = 0
for i in 0..<laps {
for s in x {
var lastBase = story._core._baseAddress
story += " "
story += s
if lastBase != story._core._baseAddress {
++reallocations
// To avoid dumping a vast string here, just write the first
// part of the story out each time there's a reallocation.
var intro = story._split(":")[0]
print("reallocation \(reallocations), with intro \(intro)")
if reallocations >= 30 {
print("Reallocations exceeded 30")
return
}
}
}
story += "."
}
print("total reallocations = \(reallocations)")
}
testReallocation()
print("done!")