Skip to content

Commit

Permalink
improve performance on line counting
Browse files Browse the repository at this point in the history
  • Loading branch information
decioferreira committed Feb 8, 2025
1 parent 93474b4 commit 7ee1263
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Compiler/Generate/JavaScript.elm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type SourceMaps

firstGeneratedLineNumber : Mode.Mode -> Int
firstGeneratedLineNumber mode =
String.length (String.filter ((==) '\n') (prelude mode)) + 1
List.length (String.lines (prelude mode))


prelude : Mode.Mode -> String
Expand Down
9 changes: 5 additions & 4 deletions src/Compiler/Generate/JavaScript/Builder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module Compiler.Generate.JavaScript.Builder exposing
-- They did the hard work of reading the spec to figure out
-- how all the types should fit together.

import Basics.Extra exposing (flip)
import Compiler.Generate.JavaScript.Name as Name
import Compiler.Json.Encode as Json
import Compiler.Reporting.Annotation as A
Expand Down Expand Up @@ -170,7 +169,7 @@ addByteString str (Builder revKernels revBuilders currentLine currentCol mapping
let
bsLines : Int
bsLines =
String.length (String.filter ((==) '\n') str)
List.length (String.lines str) - 1
in
if bsLines == 0 then
let
Expand All @@ -189,7 +188,7 @@ addTrackedByteString moduleName (A.Position line col) str (Builder revKernels re
let
bsLines : Int
bsLines =
String.length (String.filter ((==) '\n') str)
List.length (String.lines str) - 1

newMappings : List Mapping
newMappings =
Expand Down Expand Up @@ -534,7 +533,9 @@ merge a b =
linesMap : (a -> Builder -> ( Lines, Builder )) -> List a -> Bool
linesMap func xs =
List.foldl
(\a ( lines, builder ) -> func a builder |> Tuple.mapFirst (flip (::) lines))
(\a ( lines, builder ) ->
Tuple.mapFirst (\line -> line :: lines) (func a builder)
)
( [], emptyBuilder 0 )
xs
|> Tuple.first
Expand Down

0 comments on commit 7ee1263

Please sign in to comment.