Skip to content

Conversation

@Daniel-Svensson
Copy link
Contributor

Removes some copying and allocations from the lexer code which was found when trying to learn how the lexing works.

  • use existing LexemeString method in illex
  • don't create string just to access char
  • simplify eval since value is known to be '0'..'9'

I am new to F# so if there is some style issues please let me know.
If you prefer I can remove the LexemeContains and LexemeChar from lexbuf since the code can be rewritten to
just call ".Lexeme" and then index that one or do IndexOf on the span instead

Copy link
Contributor

@TIHan TIHan left a comment

Choose a reason for hiding this comment

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

This looks good, only a few minor nits.

I think the ReadOnlySpan use makes a lot of sense, but we will need to be careful as it doesn't mean the source won't change from underneath it.

Copy link
Contributor

@cartermp cartermp left a comment

Choose a reason for hiding this comment

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

Approved as well, subject to some nits. Thanks!

@forki
Copy link
Contributor

forki commented Aug 19, 2020

nice!

@brettfo brettfo changed the base branch from master to main August 19, 2020 19:58
* rename methods
* remove "new"
@Daniel-Svensson
Copy link
Contributor Author

I've updated the style and added a small change to illex .fsl for integer parsing to use span

@cartermp
Copy link
Contributor

Thanks!

@cartermp cartermp merged commit a43b60f into dotnet:main Aug 20, 2020
@Daniel-Svensson Daniel-Svensson deleted the lexer_allocations branch August 20, 2020 17:15
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Feb 23, 2021
* Reduce copying and allocations in lexing

* Simplify and improve perf of eval

* Dont create temporary array in discardInput since blit handles overlapping memory

* Fix review comments and update a new method
* rename methods
* remove "new"
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.

5 participants