@@ -434,10 +434,9 @@ private func check(input b : String, against checkStrings : [CheckString]) -> Bo
434434
435435 var i = 0
436436 var j = 0
437- var e = checkStrings. count
438437 while true {
439438 var checkRegion : String
440- if j == e {
439+ if j == checkStrings . count {
441440 checkRegion = buffer
442441 } else {
443442 let checkStr = checkStrings [ j]
@@ -452,7 +451,6 @@ private func check(input b : String, against checkStrings : [CheckString]) -> Bo
452451 return false
453452 }
454453
455-
456454 checkRegion = buffer. substring ( to: buffer. index ( buffer. startIndex, offsetBy: NSMaxRange ( range) ) )
457455 buffer = buffer. substring ( from: buffer. index ( buffer. startIndex, offsetBy: NSMaxRange ( range) ) )
458456 j += 1
@@ -472,7 +470,7 @@ private func check(input b : String, against checkStrings : [CheckString]) -> Bo
472470 checkRegion = checkRegion. substring ( from: checkRegion. index ( checkRegion. startIndex, offsetBy: NSMaxRange ( range) ) )
473471 }
474472
475- if j == e {
473+ if j == checkStrings . count {
476474 break
477475 }
478476 }
@@ -980,18 +978,19 @@ private struct CheckString {
980978
981979 /// Match check string and its "not strings" and/or "dag strings".
982980 func check( _ buffer : String , _ isLabelScanMode : Bool , _ variableTable : BoxedTable ) -> NSRange ? {
983- var lastPos = 0
984-
985- // IsLabelScanMode is true when we are scanning forward to find CHECK-LABEL
981+ // This condition is true when we are scanning forward to find CHECK-LABEL
986982 // bounds we have not processed variable definitions within the bounded block
987- // yet so cannot handle any final CHECK-DAG yetthis is handled when going
983+ // yet so cannot handle any final CHECK-DAG yet this is handled when going
988984 // over the block again (including the last CHECK-LABEL) in normal mode.
985+ let lastPos : Int
989986 if !isLabelScanMode {
990987 // Match "dag strings" (with mixed "not strings" if any).
991988 guard let lp = self . checkDAG ( buffer, variableTable) else {
992989 return nil
993990 }
994991 lastPos = lp
992+ } else {
993+ lastPos = 0
995994 }
996995
997996 // Match itself from the last position after matching CHECK-DAG.
@@ -1166,12 +1165,9 @@ private struct CheckString {
11661165 // PrintCheckFailed(SM, Pat.getLoc(), Pat, MatchBuffer, VariableTable)
11671166 return nil
11681167 }
1169- var matchPos = range. location
1170- let matchLen = range. length
1171-
1168+
11721169 // Re-calc it as the offset relative to the start of the original string.
1173- matchPos += startPos
1174-
1170+ var matchPos = range. location + startPos
11751171 if !notStrings. isEmpty {
11761172 if matchPos < lastPos {
11771173 // Reordered?
@@ -1207,7 +1203,7 @@ private struct CheckString {
12071203 }
12081204
12091205 // Update the last position with CHECK-DAG matches.
1210- lastPos = max ( matchPos + matchLen , lastPos)
1206+ lastPos = max ( matchPos + range . length , lastPos)
12111207 }
12121208
12131209 return lastPos
0 commit comments