Skip to content

Commit 3336240

Browse files
committed
[SwiftSyntax] Rename 'slapSize' to 'initialSlapSize' for clarity
1 parent 2186cc6 commit 3336240

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

Sources/SwiftParser/Lexer/LexemeSequence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension Lexer {
3030
///
3131
/// The memory footprint of not freeing past lexer states is negligible. It's
3232
/// usually less than 0.1% of the memory allocated by the syntax arena.
33-
var lexerStateAllocator = BumpPtrAllocator(slabSize: 256)
33+
var lexerStateAllocator = BumpPtrAllocator(initialSlabSize: 256)
3434

3535
/// The offset of the trailing trivia end of `nextToken` relative to the source buffer’s start.
3636
var offsetToNextTokenEnd: Int {

Sources/SwiftParser/StringLiteralRepresentedLiteralValue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ extension StringSegmentSyntax {
7979
// defensive as it's currently not used by `lexCharacterInStringLiteral`.
8080
let state = Lexer.Cursor.State.inStringLiteral(kind: stringLiteralKind, delimiterLength: delimiterLength)
8181
let transition = Lexer.StateTransition.push(newState: state)
82-
cursor.perform(stateTransition: transition, stateAllocator: BumpPtrAllocator(slabSize: 256))
82+
cursor.perform(stateTransition: transition, stateAllocator: BumpPtrAllocator(initialSlabSize: 256))
8383

8484
while true {
8585
let lex = cursor.lexCharacterInStringLiteral(

Sources/SwiftSyntax/BumpPtrAllocator.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
/// A ``BumpPtrAllocator`` that allocates `slabSize` at a time.
14+
/// `slabSize` initiates with `initialSlabSize` and doubles periodically as allocations occur.
1415
/// Once all memory in a slab has been used, it allocates a new slab and no
1516
/// memory allocations are necessary until that slab is completely filled up.
1617
@_spi(BumpPtrAllocator) @_spi(Testing)
@@ -20,8 +21,7 @@ public class BumpPtrAllocator {
2021
static private let GROWTH_DELAY: Int = 128
2122
static private let SLAB_ALIGNMENT: Int = 8
2223

23-
/// Initial slab size.
24-
private var slabSize: Int
24+
private let initialSlabSize: Int
2525

2626
private var slabs: [Slab]
2727
/// Pair of pointers in the current slab.
@@ -38,8 +38,8 @@ public class BumpPtrAllocator {
3838
private var _totalBytesAllocated: Int
3939

4040
/// Construct a new ``BumpPtrAllocator``.
41-
public init(slabSize: Int) {
42-
self.slabSize = slabSize
41+
public init(initialSlabSize: Int) {
42+
self.initialSlabSize = initialSlabSize
4343
slabs = []
4444
current = nil
4545
customSizeSlabs = []
@@ -61,7 +61,7 @@ public class BumpPtrAllocator {
6161
/// Calculate the size of the slab at the index.
6262
private func slabSize(at index: Int) -> Int {
6363
// Double the slab size every 'GROWTH_DELAY' slabs.
64-
return self.slabSize * (1 << min(30, index / Self.GROWTH_DELAY))
64+
return self.initialSlabSize * (1 << min(30, index / Self.GROWTH_DELAY))
6565
}
6666

6767
private func startNewSlab() {
@@ -114,7 +114,7 @@ public class BumpPtrAllocator {
114114
}
115115

116116
// If the size is too big, allocate a dedicated slab for it.
117-
if byteCount >= self.slabSize {
117+
if byteCount >= self.initialSlabSize {
118118
let customSlab = Slab.allocate(
119119
byteCount: byteCount,
120120
alignment: alignment

Sources/SwiftSyntax/SyntaxArena.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class SyntaxArena {
6161
}
6262

6363
fileprivate init(slabSize: Int) {
64-
self.allocator = BumpPtrAllocator(slabSize: slabSize)
64+
self.allocator = BumpPtrAllocator(initialSlabSize: slabSize)
6565
self.childRefs = []
6666
#if DEBUG || SWIFTSYNTAX_ENABLE_ASSERTIONS
6767
self.hasParent = false

Tests/SwiftSyntaxTest/BumpPtrAllocatorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import XCTest
1616
final class BumpPtrAllocatorTests: XCTestCase {
1717

1818
func testBasic() {
19-
let allocator = BumpPtrAllocator(slabSize: 4096)
19+
let allocator = BumpPtrAllocator(initialSlabSize: 4096)
2020

2121
let byteBuffer = allocator.allocate(byteCount: 42, alignment: 4)
2222
XCTAssertNotNil(byteBuffer.baseAddress)

0 commit comments

Comments
 (0)