Skip to content

Commit

Permalink
Optimize part 5.
Browse files Browse the repository at this point in the history
  • Loading branch information
hafuu committed May 30, 2017
1 parent 4ee2e10 commit 4a57c09
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
23 changes: 13 additions & 10 deletions src/FSharpApiSearch/Matcher/LowTypeMatcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ module Rules =
Debug.WriteLine("It reached the terminator.")
Failure

let testLeftEqualities (lowTypeMatcher: ILowTypeMatcher) (leftEqualities: seq<_>) right ctx =
let testLeftEqualities (lowTypeMatcher: ILowTypeMatcher) (leftEqualities: _ list) right ctx =
let mutable continue' = true
let mutable state = ctx
let e = leftEqualities.GetEnumerator()
while continue' && e.MoveNext() do
let (_, x) = e.Current
let mutable tail = leftEqualities
while continue' && not tail.IsEmpty do
let (_, x) = tail.Head
let result = lowTypeMatcher.Test right x state
match result with
| Matched ctx -> state <- ctx
| Matched ctx ->
state <- ctx
tail <- tail.Tail
| _ -> continue' <- false
if continue' then
Matched state
Expand Down Expand Up @@ -185,9 +187,10 @@ module Rules =
else
let mutable continue' = true
let mutable state = ctx, Array.empty, long, 0
let enum = (short :> seq<_>).GetEnumerator()
while continue' && enum.MoveNext() do
let testee = enum.Current
let mutable shortIndex = 0
while continue' && shortIndex < short.Length do
let testee = short.[shortIndex]
shortIndex <- shortIndex + 1
let ctx, back, forward, swapNumber = state
Debug.WriteLine(sprintf "Test %s" (testee.Debug()))
Debug.Indent()
Expand Down Expand Up @@ -503,7 +506,7 @@ let instance options =
f >> List.isEmpty >> not

let rule =
Rule.compose [
Rule.compose [|
yield Rules.choiceRule
yield Rules.typeAbbreviationRule
yield Rules.wildcardGroupRule
Expand All @@ -530,7 +533,7 @@ let instance options =
yield Rules.flexibleRule isContextual

yield Rule.terminator
]
|]

{ new ILowTypeMatcher with
member this.Test left right ctx =
Expand Down
9 changes: 5 additions & 4 deletions src/FSharpApiSearch/Matcher/MatcherTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,15 @@ module Rule =
match run rule matcher left right ctx with
| Failure -> Continue ctx
| (Matched _ | Continue _) as result -> result
let compose (xs: Rule<_, _> seq): Rule<_, _> =
let compose (xs: Rule<_, _>[]): Rule<_, _> =
fun test left right ctx ->
let mutable continue' = true
let mutable state = ctx
let mutable result = Continue ctx
let ruleEnum = xs.GetEnumerator()
while continue' && ruleEnum.MoveNext() do
let rule = ruleEnum.Current
let mutable index = 0
while continue' && index < xs.Length do
let rule = xs.[index]
index <- index + 1
let newResult = run rule test left right state
result <- newResult
match newResult with
Expand Down
4 changes: 2 additions & 2 deletions src/FSharpApiSearch/Matcher/SignatureMatcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ let instance (options: SearchOptions) =

let rec run (lowTypeMatcher: ILowTypeMatcher) (left: SignatureQuery) (right: ApiSignature) ctx =
let rule =
Rule.compose [
Rule.compose [|
yield Rules.choiceRule run

yield Rules.moduleValueRule
Expand All @@ -281,7 +281,7 @@ let instance (options: SearchOptions) =
yield Rules.typeAbbreviationRule

yield Rule.terminator
]
|]
Rule.run rule lowTypeMatcher left right ctx

{ new IApiMatcher with
Expand Down

0 comments on commit 4a57c09

Please sign in to comment.