Skip to content

Commit 31b3cc1

Browse files
committed
Replace offset(of: ) with getOffsetToStart
1 parent b0f8e70 commit 31b3cc1

File tree

2 files changed

+1
-19
lines changed

2 files changed

+1
-19
lines changed

Sources/SwiftParser/Lexer/LexemeSequence.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,6 @@ extension Lexer {
122122
return remainingText
123123
}
124124
}
125-
126-
#if SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION
127-
/// If `pointer` is in the source buffer of this ``LexemeSequence``, return
128-
/// its offset, otherwise `nil`. Should only be used for the parser's
129-
/// alternate token introspection
130-
func offset(of pointer: UnsafePointer<UInt8>) -> Int? {
131-
let offset = pointer - self.sourceBufferStart.input.baseAddress!
132-
if offset <= self.sourceBufferStart.input.count {
133-
return offset
134-
} else {
135-
return nil
136-
}
137-
}
138-
#endif
139125
}
140126

141127
@_spi(Testing)

Sources/SwiftParser/Parser.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,7 @@ public struct Parser {
250250
public var alternativeTokenChoices: [Int: [TokenSpec]] = [:]
251251

252252
mutating func recordAlternativeTokenChoice(for lexeme: Lexer.Lexeme, choices: [TokenSpec]) {
253-
guard let lexemeBaseAddress = lexeme.tokenText.baseAddress,
254-
let offset = lexemes.offset(of: lexemeBaseAddress)
255-
else {
256-
return
257-
}
253+
let offset = lexemes.getOffsetToStart(lexeme)
258254
alternativeTokenChoices[offset, default: []].append(contentsOf: choices)
259255
}
260256
#endif

0 commit comments

Comments
 (0)