Skip to content

Commit

Permalink
refactor(pkg): reuse opam buffer for parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: 112c662c-f54d-4ae3-b4bb-cf9b14c242b5 -->

Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Jan 14, 2025
1 parent 14455b3 commit 7a7cda5
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions vendor/opam-file-format/opamLexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,24 @@ module HS =
Weak.Make(struct include String let hash = Hashtbl.hash let equal = (=) end)
let hm = HS.create 317

let buf = Buffer.create 64
let m = Mutex.create ()

let buffer_rule r lb =
let pos = lb.Lexing.lex_start_p in
let b = Buffer.create 64 in
r b lb ;
(* buffer start position, instead of last lexem position *)
lb.Lexing.lex_start_p <- pos;
HS.merge hm (Buffer.contents b)
Mutex.lock m;
Buffer.clear buf;
try
r buf lb ;
(* buffer start position, instead of last lexem position *)
lb.Lexing.lex_start_p <- pos;
let contents = Buffer.contents buf in
Mutex.unlock m;
HS.merge hm contents
with
e ->
Mutex.unlock m;
raise e
}

let eol = '\r'? '\n'
Expand Down

0 comments on commit 7a7cda5

Please sign in to comment.