Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit142c139

Browse files
smoothdeveloperKevinRansom
authored andcommitted
Allow to build LexBuffer from array without copying. (dotnet#4882)
* Allow to build LexBuffer from array without copying.All usages of FromChars seem to be taking a throw away array that caller don't keep a reference, usages found:src\fsharp\lex.fsl(155)src\fsharp\UnicodeLexing.fs(18)src\fsharp\UnicodeLexing.fs(68)src\fsharp\FSharp.Compiler.Private\lex.fs(154)tests\FSharp.Compiler.UnitTests\HashIfExpression.fs(71)* remove spurious semicolons in FromArrayNoCopy* removing spurious comments
1 parent536f978 commit142c139

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

‎src/utils/prim-lexing.fs‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ namespace Internal.Utilities.Text.Lexing
145145
buffer<- repl
146146

147147

148-
// A full type signature is required on this method because it is used at more specific types within its own scope
149148
static memberFromFunction(f:'Char[]* int* int-> int):LexBuffer<'Char>=
150149
letextension= Array.zeroCreate4096
151150
letfiller(lexBuffer:LexBuffer<'Char>)=
@@ -155,15 +154,20 @@ namespace Internal.Utilities.Text.Lexing
155154
lexBuffer.BufferMaxScanLength<- lexBuffer.BufferScanLength+ n
156155
new LexBuffer<'Char>(filler)
157156

158-
//A full type signature is required on thismethodbecause it is used at more specific types within its own scope
159-
static memberFromArray(s:'Char[]):LexBuffer<'Char>=
157+
//Important: Thismethodtakes ownership of the array
158+
static memberFromArrayNoCopy(buffer:'Char[]):LexBuffer<'Char>=
160159
letlexBuffer=new LexBuffer<'Char>(fun _->())
161-
letbuffer= Array.copy s
162-
lexBuffer.Buffer<- buffer;
163-
lexBuffer.BufferMaxScanLength<- buffer.Length;
160+
lexBuffer.Buffer<- buffer
161+
lexBuffer.BufferMaxScanLength<- buffer.Length
164162
lexBuffer
165163

166-
static memberFromChars(arr:char[])= LexBuffer.FromArray arr
164+
// Important: this method does copy the array
165+
static memberFromArray(s:'Char[]):LexBuffer<'Char>=
166+
letbuffer= Array.copy s
167+
LexBuffer<'Char>.FromArrayNoCopy buffer
168+
169+
// Important: This method takes ownership of the array
170+
static memberFromChars(arr:char[])= LexBuffer.FromArrayNoCopy arr
167171

168172
moduleGenericImplFragments=
169173
letstartInterpret(lexBuffer:LexBuffer<char>)=

‎src/utils/prim-lexing.fsi‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type internal LexBuffer<'Char> =
6565
memberIsPastEndOfStream:bool with get,set
6666

6767
/// Create a lex buffer suitable for Unicode lexing that reads characters from the given array.
68+
/// Important: does take ownership of the array.
6869
static memberFromChars:char[]->LexBuffer<char>
6970
/// Create a lex buffer that reads character or byte inputs by using the given function.
7071
static memberFromFunction:('Char[]* int* int-> int)->LexBuffer<'Char>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp