From a786b136f48dfcf907dad55bcdbc4fcd247f2794 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Fri, 2 Jun 2017 13:12:11 -0400 Subject: Use lengthIs and friends in more places While investigating #12545, I discovered several places in the code that performed length-checks like so: ``` length ts == 4 ``` This is not ideal, since the length of `ts` could be much longer than 4, and we'd be doing way more work than necessary! There are already a slew of helper functions in `Util` such as `lengthIs` that are designed to do this efficiently, so I found every place where they ought to be used and did just that. I also defined a couple more utility functions for list length that were common patterns (e.g., `ltLength`). Test Plan: ./validate Reviewers: austin, hvr, goldfire, bgamari, simonmar Reviewed By: bgamari, simonmar Subscribers: goldfire, rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3622 --- compiler/main/InteractiveEval.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'compiler/main/InteractiveEval.hs') diff --git a/compiler/main/InteractiveEval.hs b/compiler/main/InteractiveEval.hs index b56d8d61e0..8b5a6b6af7 100644 --- a/compiler/main/InteractiveEval.hs +++ b/compiler/main/InteractiveEval.hs @@ -80,6 +80,7 @@ import RtClosureInspect import Outputable import FastString import Bag +import Util import qualified Lexer (P (..), ParseResult(..), unP, mkPState) import qualified Parser (parseStmt, parseModule, parseDeclaration, parseImport) @@ -400,7 +401,7 @@ moveHist fn = do history = resumeHistory r new_ix = fn ix -- - when (new_ix > length history) $ liftIO $ + when (history `lengthLessThan` new_ix) $ liftIO $ throwGhcExceptionIO (ProgramError "no more logged breakpoints") when (new_ix < 0) $ liftIO $ throwGhcExceptionIO (ProgramError "already at the beginning of the history") -- cgit v1.2.1