life if-statement up (so that the test is only done once, to help the branch predictor)
This commit is contained in:
BIN
bench/line_gap_svelte
Executable file
BIN
bench/line_gap_svelte
Executable file
Binary file not shown.
BIN
bench/line_rope_svelte
Executable file
BIN
bench/line_rope_svelte
Executable file
Binary file not shown.
@@ -41,7 +41,6 @@ struct
|
|||||||
, rightLines: int vector list
|
, rightLines: int vector list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val stringLimit = 1024
|
val stringLimit = 1024
|
||||||
val vecLimit = 32
|
val vecLimit = 32
|
||||||
|
|
||||||
@@ -268,33 +267,41 @@ struct
|
|||||||
then
|
then
|
||||||
(* If we can join newString/lines with sub1 while
|
(* If we can join newString/lines with sub1 while
|
||||||
* staying in limit. *)
|
* staying in limit. *)
|
||||||
let
|
|
||||||
val newLeftLines =
|
|
||||||
if midpoint >= 0 then
|
if midpoint >= 0 then
|
||||||
(* Implicit: a binSearch match was found. *)
|
(* Implicit: a binSearch match was found. *)
|
||||||
let
|
let
|
||||||
val newLeftLinesLength = midpoint + 1 + Vector.length newLines
|
val newLeftLinesLength = midpoint + 1 + Vector.length newLines
|
||||||
in
|
val newLeftLines = Vector.tabulate (newLeftLinesLength, fn idx =>
|
||||||
Vector.tabulate (newLeftLinesLength, fn idx =>
|
|
||||||
if idx <= midpoint then
|
if idx <= midpoint then
|
||||||
Vector.sub (leftLinesHd, idx)
|
Vector.sub (leftLinesHd, idx)
|
||||||
else
|
else
|
||||||
Vector.sub (newLines, idx - (midpoint + 1))
|
Vector.sub (newLines, idx - (midpoint + 1))
|
||||||
+ String.size strSub1)
|
+ String.size strSub1)
|
||||||
end
|
|
||||||
else
|
|
||||||
Vector.map (fn el => el + String.size strSub1) newLines
|
|
||||||
|
|
||||||
val newRightLines =
|
val newRightLines =
|
||||||
if midpoint >= 0 then
|
|
||||||
(* Implicit: a binSearch match was found. *)
|
|
||||||
Vector.tabulate
|
Vector.tabulate
|
||||||
( (Vector.length leftLinesHd - midpoint) - 1
|
( (Vector.length leftLinesHd - midpoint) - 1
|
||||||
, fn idx =>
|
, fn idx =>
|
||||||
Vector.sub (leftLinesHd, idx + midpoint + 1)
|
Vector.sub (leftLinesHd, idx + midpoint + 1)
|
||||||
- String.size strSub1
|
- String.size strSub1
|
||||||
)
|
)
|
||||||
|
in
|
||||||
|
{ idx = prevIdx + String.size strSub1 + String.size newString
|
||||||
|
, line =
|
||||||
|
(curLine - Vector.length leftLinesHd)
|
||||||
|
+ Vector.length newLeftLines
|
||||||
|
, leftStrings = (strSub1 ^ newString) :: leftStringsTl
|
||||||
|
, leftLines = newLeftLines :: leftLinesTl
|
||||||
|
, rightStrings = strSub2 :: rightStrings
|
||||||
|
, rightLines = newRightLines :: rightLines
|
||||||
|
}
|
||||||
|
end
|
||||||
else
|
else
|
||||||
|
let
|
||||||
|
(* No binSearch result found. *)
|
||||||
|
val newLeftLines =
|
||||||
|
Vector.map (fn el => el + String.size strSub1) newLines
|
||||||
|
val newRightLines =
|
||||||
Vector.map (fn idx => idx - String.size strSub1) leftLinesHd
|
Vector.map (fn idx => idx - String.size strSub1) leftLinesHd
|
||||||
in
|
in
|
||||||
{ idx = prevIdx + String.size strSub1 + String.size newString
|
{ idx = prevIdx + String.size strSub1 + String.size newString
|
||||||
@@ -594,35 +601,42 @@ struct
|
|||||||
then
|
then
|
||||||
(* If we can join newString/lines with sub1 while
|
(* If we can join newString/lines with sub1 while
|
||||||
* staying in limit. *)
|
* staying in limit. *)
|
||||||
let
|
|
||||||
(* strSub1 ^ newString is placed on the left list. *)
|
|
||||||
val newLeftStringsHd = strSub1 ^ newString
|
|
||||||
val newLeftLinesHd =
|
|
||||||
if midpoint >= 0 then
|
if midpoint >= 0 then
|
||||||
(* Implicit: a binSearch match was found. *)
|
|
||||||
let
|
let
|
||||||
|
(* Implicit: a binSearch match was found. *)
|
||||||
|
val newLeftStringsHd = strSub1 ^ newString
|
||||||
val newLeftLinesLength = midpoint + 1 + Vector.length newLines
|
val newLeftLinesLength = midpoint + 1 + Vector.length newLines
|
||||||
in
|
val newLeftLinesHd =
|
||||||
Vector.tabulate (newLeftLinesLength, fn idx =>
|
Vector.tabulate (newLeftLinesLength, fn idx =>
|
||||||
if idx <= midpoint then
|
if idx <= midpoint then
|
||||||
Vector.sub (rightLinesHd, idx)
|
Vector.sub (rightLinesHd, idx)
|
||||||
else
|
else
|
||||||
Vector.sub (newLines, idx - (midpoint + 1))
|
Vector.sub (newLines, idx - (midpoint + 1))
|
||||||
+ String.size strSub1)
|
+ String.size strSub1)
|
||||||
end
|
|
||||||
else
|
|
||||||
Vector.map (fn el => el + String.size strSub1) newLines
|
|
||||||
|
|
||||||
val newRightLinesHd =
|
val newRightLinesHd =
|
||||||
if midpoint >= 0 then
|
|
||||||
(* Implicit: a binSearch match was found. *)
|
|
||||||
Vector.tabulate
|
Vector.tabulate
|
||||||
( (Vector.length rightLinesHd - midpoint) - 1
|
( (Vector.length rightLinesHd - midpoint) - 1
|
||||||
, fn idx =>
|
, fn idx =>
|
||||||
Vector.sub (rightLinesHd, idx + midpoint + 1)
|
Vector.sub (rightLinesHd, idx + midpoint + 1)
|
||||||
- String.size strSub1
|
- String.size strSub1
|
||||||
)
|
)
|
||||||
|
in
|
||||||
|
{ idx = curIdx + String.size newLeftStringsHd
|
||||||
|
, line = curLine + Vector.length newLeftLinesHd
|
||||||
|
, leftStrings = newLeftStringsHd :: leftStrings
|
||||||
|
, leftLines = newLeftLinesHd :: leftLines
|
||||||
|
, rightStrings = strSub2 :: rightStringsTl
|
||||||
|
, rightLines = newRightLinesHd :: rightLinesTl
|
||||||
|
}
|
||||||
|
end
|
||||||
else
|
else
|
||||||
|
let
|
||||||
|
(* No binSearch match found. *)
|
||||||
|
val newLeftStringsHd = strSub1 ^ newString
|
||||||
|
val newLeftLinesHd =
|
||||||
|
Vector.map (fn el => el + String.size strSub1) newLines
|
||||||
|
val newRightLinesHd =
|
||||||
Vector.map (fn idx => idx - String.size strSub1) rightLinesHd
|
Vector.map (fn idx => idx - String.size strSub1) rightLinesHd
|
||||||
in
|
in
|
||||||
{ idx = curIdx + String.size newLeftStringsHd
|
{ idx = curIdx + String.size newLeftStringsHd
|
||||||
@@ -668,7 +682,6 @@ struct
|
|||||||
+ Vector.length newLeftLinesHd
|
+ Vector.length newLeftLinesHd
|
||||||
) - String.size strSub1) + String.size newString
|
) - String.size strSub1) + String.size newString
|
||||||
)
|
)
|
||||||
|
|
||||||
in
|
in
|
||||||
{ idx = curIdx + String.size strSub1
|
{ idx = curIdx + String.size strSub1
|
||||||
, line = curLine + Vector.length newLeftLinesHd
|
, line = curLine + Vector.length newLeftLinesHd
|
||||||
|
|||||||
Reference in New Issue
Block a user