on master help sign in
Merge pull request #57 from ethercrow/large-input-performance

When looking at input for an event, don't look too deep.

commitfe8b129bf606ea25088f4846fa66c533285a335a authorCorey O'Connor <coreyoconnor@gmail.com> dateSun 21 Sep 2014, 14:40 (12 years ago) parent6ba874cbb55988
1 file changed+2−1
src/Graphics/Vty/Input/Classify.hs+2−1
src/Graphics/Vty/Input/Classify.hs+2−1
@@ -30,6 +30,7 @@ compile :: ClassifyMap -> [Char] -> KClass
3030compile table = cl' where
3131 -- take all prefixes and create a set of these
3232 prefixSet = S.fromList $ concatMap (init . inits . fst) $ table
33+ maxValidInputLength = maximum (map (length . fst) table)
3334 eventForInput = M.fromList table
3435 cl' [] = Prefix
3536 cl' inputBlock = case M.lookup inputBlock eventForInput of
@@ -45,7 +46,7 @@ compile table = cl' where
4546 -- H: There will always be one match. The prefixSet contains, by definition, all
4647 -- prefixes of an event.
4748 False ->
48− let inputPrefixes = reverse $ tail $ inits inputBlock
49+ let inputPrefixes = reverse $ take maxValidInputLength $ tail $ inits inputBlock
4950 in case mapMaybe (\s -> (,) s `fmap` M.lookup s eventForInput) inputPrefixes of
5051 (s,e) : _ -> Valid e (drop (length s) inputBlock)
5152 -- neither a prefix or a full event.