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

Commitc1b5aa5

Browse files
TIHanKevinRansom
authored andcommitted
Improved performance of splitAroundQuotation (dotnet#5599)
* Improved performance of splitAroundQuotation* Get tests passing
1 parentc9822c8 commitc1b5aa5

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

‎src/fsharp/PrettyNaming.fs‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -544,21 +544,31 @@ module public Microsoft.FSharp.Compiler.PrettyNaming
544544

545545
/// Return a string array delimited by the given separator.
546546
/// Note that a quoted string is not going to be mangled into pieces.
547+
let inlineprivateisNotQuotedQuotation(text:string)n= n>0&& text.[n-1]<>'\\'
547548
letprivatesplitAroundQuotation(text:string)(separator:char)=
548549
letlength= text.Length
549-
letisNotQuotedQuotation n= n>0&& text.[n-1]<>'\\'
550-
let recsplit(i,cur,group,insideQuotation)=
551-
if i>=lengththen List.rev(cur::group)else
550+
letresult= ResizeArray()
551+
let mutableinsideQuotation=false
552+
let mutablestart=0
553+
for i=0to length-1do
552554
match text.[i], insideQuotationwith
553555
// split when seeing a separator
554-
| c,falsewhen c= separator-> split(i+1,"", cur::group,false)
556+
| c,falsewhen c= separator->
557+
result.Add(text.Substring(start, i- start))
558+
insideQuotation<-false
559+
start<- i+1
560+
|_,_when i= length-1->
561+
result.Add(text.Substring(start, i- start+1))
555562
// keep reading if a separator is inside quotation
556-
| c,truewhen c= separator-> split(i+1, cur+(Char.ToString c), group,true)
557-
// open or close quotation
558-
|'\"',_when isNotQuotedQuotation i-> split(i+1, cur+"\"", group,not insideQuotation)
563+
| c,truewhen c= separator->
564+
insideQuotation<-true
565+
// open or close quotation
566+
|'\"',_when isNotQuotedQuotation text i->
567+
insideQuotation<-not insideQuotation
559568
// keep reading
560-
| c,_-> split(i+1, cur+(Char.ToString c), group, insideQuotation)
561-
split(0,"",[],false)|> Array.ofList
569+
|_->()
570+
571+
result.ToArray()
562572

563573
/// Return a string array delimited by the given separator up to the maximum number.
564574
/// Note that a quoted string is not going to be mangled into pieces.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp