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

Commit87ea864

Browse files
AviAvniTIHan
authored andcommitted
Remove massive string allocations (dotnet#5940)
* remove massive string allocations* change NormalizedSource Source and Seq to Array computation expression* fix line end according to the source positions* remove pos use i* fix some tests
1 parentb630ce1 commit87ea864

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

‎src/fsharp/CheckFormatStrings.fs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ let parseFormatStringInternal (m:range) (g: TcGlobals) (context: FormatStringChe
5454
let(offset,fmt)=
5555
match contextwith
5656
| Some context->
57-
letlength= context.NormalizedSource.Length
58-
if m.EndLine< context.LineEndPositions.Lengththen
59-
letstartIndex= context.LineEndPositions.[m.StartLine-1]+ m.StartColumn
60-
letendIndex= context.LineEndPositions.[m.EndLine-1]+ m.EndColumn-1
61-
if startIndex< length-3&& context.NormalizedSource.[startIndex..startIndex+2]="\"\"\""then
62-
(3, context.NormalizedSource.[startIndex+3..endIndex-3])
63-
elif startIndex< length-2&& context.NormalizedSource.[startIndex..startIndex+1]="@\""then
64-
(2, context.NormalizedSource.[startIndex+2..endIndex-1])
65-
else(1, context.NormalizedSource.[startIndex+1..endIndex-1])
57+
letlength= context.Source.Length
58+
if m.EndLine< context.LineStartPositions.Lengththen
59+
letstartIndex= context.LineStartPositions.[m.StartLine-1]+ m.StartColumn
60+
letendIndex= context.LineStartPositions.[m.EndLine-1]+ m.EndColumn-1
61+
if startIndex< length-3&& context.Source.[startIndex..startIndex+2]="\"\"\""then
62+
(3, context.Source.[startIndex+3..endIndex-3])
63+
elif startIndex< length-2&& context.Source.[startIndex..startIndex+1]="@\""then
64+
(2, context.Source.[startIndex+2..endIndex-1])
65+
else(1, context.Source.[startIndex+1..endIndex-1])
6666
else(1, fmt)
6767
| None->(1, fmt)
6868

‎src/fsharp/NameResolution.fs‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,8 +1251,8 @@ type OpenDeclaration =
12511251
IsOwnNamespace= isOwnNamespace}
12521252

12531253
typeFormatStringCheckContext=
1254-
{NormalizedSource:string
1255-
LineEndPositions:int[]}
1254+
{Source:string
1255+
LineStartPositions:int[]}
12561256

12571257
/// An abstract type for reporting the results of name resolution and type checking.
12581258
typeITypecheckResultsSink=
@@ -1538,14 +1538,18 @@ type TcResultsSinkImpl(g, ?source: string) =
15381538
letformatStringCheckContext=
15391539
lazy
15401540
source|> Option.map(fun source->
1541-
letsource= source.Replace("\r\n","\n").Replace("\r","\n")
15421541
letpositions=
1543-
source.Split('\n')
1544-
|> Seq.map(fun s-> String.length s+1)
1545-
|> Seq.scan(+)0
1546-
|> Seq.toArray
1547-
{ NormalizedSource= source
1548-
LineEndPositions= positions})
1542+
[|
1543+
yield0
1544+
for iin0..source.Length-1do
1545+
letc= source.[i]
1546+
if c='\r'&& i+1< source.Length&& source.[i+1]='\n'then()
1547+
elif c='\r'thenyield i+1
1548+
if c='\n'thenyield i+1
1549+
yield source.Length
1550+
|]
1551+
{ Source= source
1552+
LineStartPositions= positions})
15491553

15501554
memberthis.GetResolutions()=
15511555
TcResolutions(capturedEnvs, capturedExprTypings, capturedNameResolutions, capturedMethodGroupResolutions)

‎src/fsharp/NameResolution.fsi‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,12 @@ type internal OpenDeclaration =
344344
/// Create a new instance of OpenDeclaration.
345345
static memberCreate:longId:Ident list* modules: ModuleOrNamespaceRef list* appliedScope: range* isOwnNamespace: bool-> OpenDeclaration
346346
347-
///Line-end normalized source text and an array of line end positions, used for format string parsing
347+
///Source text and an array of line end positions, used for format string parsing
348348
type FormatStringCheckContext=
349-
{///Line-end normalized source text
350-
NormalizedSource:string
351-
/// Array of lineend positions
352-
LineEndPositions:int[]}
349+
{///Source text
350+
Source:string
351+
/// Array of linestart positions
352+
LineStartPositions:int[]}
353353

354354
/// An abstract type for reporting the results of name resolution and type checking
355355
typeITypecheckResultsSink=

‎tests/service/EditorTests.fs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,7 @@ let _ = printf " %*a" 3 (fun _ _ -> ()) 2
433433
typeCheckResults.GetFormatSpecifierLocationsAndArity()
434434
|> Array.map(fun(range,numArgs)-> range.StartLine, range.StartColumn, range.EndLine, range.EndColumn, numArgs)
435435
|> shouldEqual
436-
[|(2,45,2,47,1);(3,23,3,25,1);(4,38,4,40,1);(5,27,5,29
437-
,1);
436+
[|(2,45,2,47,1);(3,23,3,25,1);(4,38,4,40,1);(5,27,5,29,1);
438437
(6,17,6,20,2);(7,17,7,22,1);(8,17,8,23,1);(9,18,9,22,1);
439438
(10,18,10,21,1);(12,12,12,15,1);(15,12,15,15,1);
440439
(16,28,16,30,1);(18,30,18,32,1);(19,30,19,32,1);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp