Skip to content

Conversation

@Thorium
Copy link
Member

@Thorium Thorium commented Nov 11, 2025

This fixes #964

Copy link
Collaborator

@nojaf nojaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the way to go.
I'd prefer a solution where everything happens in one pass.

// Fast path: check if string needs encoding at all
let needsEncoding =
text
|> Seq.exists (fun c ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scans the string to check if encoding is needed, but you traverse it again when you encoding.
Can we do this in one pass?
I'm a little afraid this code is in a hot path.

Copy link
Member Author

@Thorium Thorium Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question I had is that, expecting this is a minor use-case (but AI does more and more documentation in the future) is it worth of checking every character ever that goes through formatting? Will it slowdown the process? So could we do somehow like a high-level check, if the replacement-run is relevant at all?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking every character ever that goes through Fantomas?

What do you mean here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I meant F# Formatting of course not Fantomas. I was thinkin only in context of html generation: It is called in basically every .NET tool build-scripts, we want it to be fast if possible.

then
let fullCodePoint = Char.ConvertToUtf32(c, text.[i + 1])
// Encode all characters outside BMP (>= 0x10000) as they're typically emojis
sb.Append(sprintf "&#%d;" fullCodePoint) |> ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't sprintf allocating here and beats the point of the StringBuilder a bit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of that. I've tried to check the sprintf with https://sharplab.io/ before, but I wasn't convinced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conversions from fsx comments markdown to html on AI-generated documents

2 participants