Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 756b07a

Browse files
committed
Make Printer.classifyIdentContent much more readable
Not much perf difference. Slightly faster?
1 parent 1cec130 commit 756b07a

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/res_printer.ml

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -355,30 +355,23 @@ type identifierStyle =
355355
| NormalIdent
356356

357357
let classifyIdentContent ?(allowUident=false) txt =
358-
let len = String.length txt in
359-
let rec go i =
360-
if i == len then NormalIdent
361-
else
362-
let c = String.unsafe_get txt i in
363-
if i == 0 && not (
364-
(allowUident && (c >= 'A' && c <= 'Z')) ||
365-
(c >= 'a' && c <= 'z') || c = '_' ) then
366-
ExoticIdent
367-
else if not (
368-
(c >= 'a' && c <= 'z')
369-
|| (c >= 'A' && c <= 'Z')
370-
|| c = '\''
371-
|| c = '_'
372-
|| (c >= '0' && c <= '9'))
373-
then
374-
ExoticIdent
375-
else
376-
go (i + 1)
377-
in
378358
if Token.isKeywordTxt txt then
379359
ExoticIdent
380360
else
381-
go 0
361+
let len = String.length txt in
362+
let rec loop i =
363+
if i == len then NormalIdent
364+
else if i == 0 then
365+
match String.unsafe_get txt i with
366+
| 'A'..'Z' when allowUident -> loop (i + 1)
367+
| 'a'..'z' | '_' -> loop (i + 1)
368+
| _ -> ExoticIdent
369+
else
370+
match String.unsafe_get txt i with
371+
| 'A'..'Z' | 'a'..'z' | '0'..'9' | '\'' | '_' -> loop (i + 1)
372+
| _ -> ExoticIdent
373+
in
374+
loop 0
382375

383376
let printIdentLike ?allowUident txt =
384377
match classifyIdentContent ?allowUident txt with

0 commit comments

Comments
 (0)