Skip to content

Commit b4c7c8c

Browse files
committed
Cleanup
1 parent 3e1e088 commit b4c7c8c

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

Sources/_StringProcessing/ByteCodeGen.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,19 @@ fileprivate extension Compiler.ByteCodeGen {
9494
}
9595
} else {
9696
if optimizationsEnabled && s.allSatisfy({char in char.isASCII}) {
97-
for char in s {
97+
for char in s.dropLast(1) {
9898
// Note: only cr-lf is multiple scalars
9999
for scalar in char.unicodeScalars {
100-
// Only boundary check if we are the last scalar in the last character
101-
// to make sure that there isn't a combining scalar after the quoted literal
102-
let boundaryCheck = char == s.last! && scalar == char.unicodeScalars.last!
103-
builder.buildMatchScalar(scalar, boundaryCheck: boundaryCheck)
100+
builder.buildMatchScalar(scalar, boundaryCheck: false)
104101
}
105102
}
103+
let lastChar = s.last!
104+
for scalar in lastChar.unicodeScalars {
105+
// Only boundary check if we are the last scalar in the last character
106+
// to make sure that there isn't a combining scalar after the quoted literal
107+
let boundaryCheck = scalar == lastChar.unicodeScalars.last!
108+
builder.buildMatchScalar(scalar, boundaryCheck: boundaryCheck)
109+
}
106110
} else {
107111
builder.buildMatchSequence(s)
108112
}
@@ -286,7 +290,7 @@ fileprivate extension Compiler.ByteCodeGen {
286290
return
287291
}
288292

289-
if optimizationsEnabled { // lily note: should we just do this unconditionally?
293+
if optimizationsEnabled { // should we just do this unconditionally?
290294
builder.buildMatchScalar(s, boundaryCheck: false)
291295
} else {
292296
builder.buildConsume(by: consumeScalar {

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313

1414
extension Character {
1515
var singleScalarAsciiValue: UInt8? {
16-
if let val = asciiValue, self != "\r\n" {
17-
return val
18-
}
19-
return nil
16+
guard self != "\r\n" else { return nil }
17+
return asciiValue
2018
}
2119
}
2220

23-
2421
extension DSLTree.Node {
2522
/// Attempt to generate a consumer from this AST node
2623
///

0 commit comments

Comments
 (0)