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

Commitab48458

Browse files
auduchinokKevinRansom
authored andcommitted
Use ordinal string comparison in string manipulation methods (#4912)
* Use ordinal string comparison in string manipulation methodsStartsWith, EndsWith, Compare, etc* Add StartsWithOrdinal, EndsWithOrdinal extension methods
1 parent61a165e commitab48458

36 files changed

+145
-123
lines changed

‎fcs/FSharp.Compiler.Service.ProjectCrackerTool/Program.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module Program =
1010
letaddMSBuildv14BackupResolution()=
1111
letonResolveEvent=new ResolveEventHandler(fun sender evArgs->
1212
letrequestedAssembly= AssemblyName(evArgs.Name)
13-
if requestedAssembly.Name.StartsWith("Microsoft.Build")&&
14-
not(requestedAssembly.Name.EndsWith(".resources"))&&
13+
if requestedAssembly.Name.StartsWith("Microsoft.Build", StringComparison.Ordinal)&&
14+
not(requestedAssembly.Name.EndsWith(".resources", StringComparison.Ordinal))&&
1515
not(requestedAssembly.Version.ToString().Contains("12.0.0.0"))
1616
then
1717
// If the version of MSBuild that we're using wasn't present on the machine, then

‎src/absil/il.fs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@ type AssemblyRefData =
356356
letAssemblyRefUniqueStampGenerator=new UniqueStampGenerator<AssemblyRefData>()
357357

358358
letisMscorlib data=
359-
if System.String.Compare(data.assemRefName,"mscorlib")=0thentrue
360-
elsefalse
359+
data.assemRefName="mscorlib"
361360

362361
[<Sealed>]
363362
typeILAssemblyRef(data)=

‎src/absil/illib.fs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,13 @@ module ValueOption =
445445
let inlineofOption x=match xwith Some x-> ValueSome x| None-> ValueNone
446446
let inlinebind f x=match xwith ValueSome x-> f x| ValueNone-> ValueNone
447447

448+
typeStringwith
449+
member inlinex.StartsWithOrdinal(value)=
450+
x.StartsWith(value, StringComparison.Ordinal)
451+
452+
member inlinex.EndsWithOrdinal(value)=
453+
x.EndsWith(value, StringComparison.Ordinal)
454+
448455
moduleString=
449456
letindexNotFound()= raise(new KeyNotFoundException("An index for the character was not found in the string"))
450457

@@ -524,7 +531,7 @@ module String =
524531
let(|StartsWith|_|)pattern value=
525532
if String.IsNullOrWhiteSpace valuethen
526533
None
527-
elif value.StartsWithpatternthen
534+
elif value.StartsWithOrdinal(pattern)then
528535
Some()
529536
else None
530537

@@ -542,7 +549,7 @@ module String =
542549
whilenot(isNull!line)do
543550
yield!line
544551
line:= reader.ReadLine()
545-
if str.EndsWith("\n")then
552+
if str.EndsWithOrdinal("\n")then
546553
// last trailing space not returned
547554
// http://stackoverflow.com/questions/19365404/stringreader-omits-trailing-linebreak
548555
yield String.Empty

‎src/absil/ilreflect.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ let rec emitInstr cenv (modB : ModuleBuilder) emEnv (ilG:ILGenerator) instr =
12961296
ignore src
12971297
()
12981298
#else
1299-
if cenv.generatePdb&&not(src.Document.File.EndsWith("stdin", StringComparison.Ordinal))then
1299+
if cenv.generatePdb&&not(src.Document.File.EndsWithOrdinal("stdin"))then
13001300
letguid x=match xwith None-> Guid.Empty| Some g-> Guid(g:byte[])in
13011301
letsymDoc= modB.DefineDocumentAndLog(src.Document.File, guid src.Document.Language, guid src.Document.Vendor, guid src.Document.DocumentType)
13021302
ilG.MarkSequencePointAndLog(symDoc, src.Line, src.Column, src.EndLine, src.EndColumn)

‎src/fsharp/CompileOps.fs‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ let OutputPhasedErrorR (os:StringBuilder) (err:PhasedDiagnostic) =
695695
| ContextInfo.TupleInRecordFields->
696696
os.Append(ErrorFromAddingTypeEquation1E().Format t2 t1 tpcs)|> ignore
697697
os.Append(System.Environment.NewLine+ FSComp.SR.commaInsteadOfSemicolonInRecord())|> ignore
698-
|_when t2="bool"&& t1.EndsWith" ref"->
698+
|_when t2="bool"&& t1.EndsWithOrdinal(" ref")->
699699
os.Append(ErrorFromAddingTypeEquation1E().Format t2 t1 tpcs)|> ignore
700700
os.Append(System.Environment.NewLine+ FSComp.SR.derefInsteadOfNot())|> ignore
701701
|_-> os.Append(ErrorFromAddingTypeEquation1E().Format t2 t1 tpcs)|> ignore
@@ -1604,7 +1604,7 @@ let SanitizeFileName fileName implicitIncludeDir =
16041604
letcurrentDir= implicitIncludeDir
16051605

16061606
// if the file name is not rooted in the current directory, return the full path
1607-
ifnot(fullPath.StartsWith(currentDir))then
1607+
ifnot(fullPath.StartsWithOrdinal(currentDir))then
16081608
fullPath
16091609
// if the file name is rooted in the current directory, return the relative path
16101610
else
@@ -1796,7 +1796,7 @@ type private TypeInThisAssembly = class end
17961796
letGetDefaultSystemValueTupleReference()=
17971797
try
17981798
letasm= typeof<System.ValueTuple<int, int>>.Assembly
1799-
if asm.FullName.StartsWith"System.ValueTuple"then
1799+
if asm.FullName.StartsWithOrdinal("System.ValueTuple")then
18001800
Some asm.Location
18011801
else
18021802
letlocation= Path.GetDirectoryName(typeof<TypeInThisAssembly>.Assembly.Location)
@@ -2025,7 +2025,7 @@ let GetWarningNumber(m, s:string) =
20252025
// therefore if we have warning id that starts with a numeric digit we convert it to Some (int32)
20262026
// anything else is ignored None
20272027
if Char.IsDigit(s.[0])then Some(int32 s)
2028-
elif s.StartsWith("FS", StringComparison.Ordinal)=truethen raise(new ArgumentException())
2028+
elif s.StartsWithOrdinal("FS")=truethen raise(new ArgumentException())
20292029
else None
20302030
with err->
20312031
warning(Error(FSComp.SR.buildInvalidWarningNumber(s), m))
@@ -3748,28 +3748,29 @@ type TcAssemblyResolutions(tcConfig: TcConfig, results: AssemblyResolution list,
37483748
//--------------------------------------------------------------------------
37493749

37503750
letIsSignatureDataResource(r:ILResource)=
3751-
r.Name.StartsWithFSharpSignatureDataResourceName||
3752-
r.Name.StartsWithFSharpSignatureDataResourceName2
3751+
r.Name.StartsWithOrdinal(FSharpSignatureDataResourceName)||
3752+
r.Name.StartsWithOrdinal(FSharpSignatureDataResourceName2)
37533753

37543754
letIsOptimizationDataResource(r:ILResource)=
3755-
r.Name.StartsWithFSharpOptimizationDataResourceName||
3756-
r.Name.StartsWithFSharpOptimizationDataResourceName2
3755+
r.Name.StartsWithOrdinal(FSharpOptimizationDataResourceName)||
3756+
r.Name.StartsWithOrdinal(FSharpOptimizationDataResourceName2)
37573757

37583758
letGetSignatureDataResourceName(r:ILResource)=
3759-
if r.Name.StartsWithFSharpSignatureDataResourceNamethen
3759+
if r.Name.StartsWithOrdinal(FSharpSignatureDataResourceName)then
37603760
String.dropPrefix r.Name FSharpSignatureDataResourceName
3761-
elif r.Name.StartsWithFSharpSignatureDataResourceName2then
3761+
elif r.Name.StartsWithOrdinal(FSharpSignatureDataResourceName2)then
37623762
String.dropPrefix r.Name FSharpSignatureDataResourceName2
37633763
else failwith"GetSignatureDataResourceName"
37643764

37653765
letGetOptimizationDataResourceName(r:ILResource)=
3766-
if r.Name.StartsWithFSharpOptimizationDataResourceNamethen
3766+
if r.Name.StartsWithOrdinal(FSharpOptimizationDataResourceName)then
37673767
String.dropPrefix r.Name FSharpOptimizationDataResourceName
3768-
elif r.Name.StartsWithFSharpOptimizationDataResourceName2then
3768+
elif r.Name.StartsWithOrdinal(FSharpOptimizationDataResourceName2)then
37693769
String.dropPrefix r.Name FSharpOptimizationDataResourceName2
37703770
else failwith"GetOptimizationDataResourceName"
37713771

3772-
letIsReflectedDefinitionsResource(r:ILResource)= r.Name.StartsWith QuotationPickler.SerializedReflectedDefinitionsResourceNameBase
3772+
letIsReflectedDefinitionsResource(r:ILResource)=
3773+
r.Name.StartsWithOrdinal(QuotationPickler.SerializedReflectedDefinitionsResourceNameBase)
37733774

37743775
letMakeILResource rname bytes=
37753776
{ Name= rname

‎src/fsharp/CompileOptions.fs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ module ResponseFile =
188188
letparseLine(l:string)=
189189
match lwith
190190
| swhen String.IsNullOrWhiteSpace(s)-> None
191-
| swhen l.StartsWith("#")-> Some(ResponseFileLine.Comment(s.TrimStart('#')))
191+
| swhen l.StartsWithOrdinal("#")-> Some(ResponseFileLine.Comment(s.TrimStart('#')))
192192
| s-> Some(ResponseFileLine.CompilerOptionSpec(s.Trim()))
193193

194194
try
@@ -224,7 +224,7 @@ let ParseCompilerOptions (collectOtherArgument : string -> unit, blocks: Compile
224224
if opt.Length=2|| isSlashOpt optthen
225225
opt<- opt.[1..]
226226
// else, it should be a non-abbreviated option starting with "--"
227-
elif opt.Length>3&& opt.StartsWith("--")then
227+
elif opt.Length>3&& opt.StartsWithOrdinal("--")then
228228
opt<- opt.[2..]
229229
else
230230
opt<-""
@@ -247,19 +247,19 @@ let ParseCompilerOptions (collectOtherArgument : string -> unit, blocks: Compile
247247

248248
letgetSwitchOpt(opt:string)=
249249
// if opt is a switch, strip the '+' or '-'
250-
if opt<>"--"&& opt.Length>1&&(opt.EndsWith("+",StringComparison.Ordinal)|| opt.EndsWith("-",StringComparison.Ordinal))then
250+
if opt<>"--"&& opt.Length>1&&(opt.EndsWithOrdinal("+")|| opt.EndsWithOrdinal("-"))then
251251
opt.[0.. opt.Length-2]
252252
else
253253
opt
254254

255255
letgetSwitch(s:string)=
256256
lets=(s.Split([|':'|])).[0]
257-
if s<>"--"&& s.EndsWith("-",StringComparison.Ordinal)then OptionSwitch.Offelse OptionSwitch.On
257+
if s<>"--"&& s.EndsWithOrdinal("-")then OptionSwitch.Offelse OptionSwitch.On
258258

259259
let recprocessArg args=
260260
match argswith
261261
|[]->()
262-
|((rsp: string):: t)when rsp.StartsWith("@")->
262+
|((rsp: string):: t)when rsp.StartsWithOrdinal("@")->
263263
letresponseFileOptions=
264264
letfullpath=
265265
try
@@ -555,7 +555,7 @@ let inputFileFlagsFsc tcConfigB = inputFileFlagsBoth tcConfigB
555555
//---------------------------------
556556

557557
leterrorsAndWarningsFlags(tcConfigB:TcConfigBuilder)=
558-
lettrimFS(s:string)=if s.StartsWith("FS", StringComparison.Ordinal)=truethen s.Substring(2)else s
558+
lettrimFS(s:string)=if s.StartsWithOrdinal("FS")=truethen s.Substring(2)else s
559559
lettrimFStoInt(s:string)=
560560
try
561561
Some(int32(trimFS s))

‎src/fsharp/ConstraintSolver.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,8 @@ and SolveMemberConstraint (csenv:ConstraintSolverEnv) ignoreUnresolvedOverload p
12411241

12421242
// First look for a solution by a record property
12431243
letrecdPropSearch=
1244-
letisGetProp= nm.StartsWith"get_"
1245-
letisSetProp= nm.StartsWith"set_"
1244+
letisGetProp= nm.StartsWithOrdinal("get_")
1245+
letisSetProp= nm.StartsWithOrdinal("set_")
12461246
if argtys.IsEmpty&& isGetProp|| isSetPropthen
12471247
letpropName= nm.[4..]
12481248
letprops=

‎src/fsharp/ErrorResolutionHints.fs‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
moduleinternalMicrosoft.FSharp.Compiler.ErrorResolutionHints
55

66
openInternal.Utilities
7+
openMicrosoft.FSharp.Compiler.AbstractIL.Internal.Library
78

89
letmaxSuggestions=5
910
letminThresholdForSuggestions=0.7
@@ -28,17 +29,18 @@ let FilterPredictions (idText:string) (suggestionF:ErrorLogger.Suggestions) =
2829
letallSuggestions= suggestionF()
2930

3031
letdemangle(nm:string)=
31-
if nm.StartsWith"("&& nm.EndsWith" )"then
32+
if nm.StartsWithOrdinal("(")&& nm.EndsWithOrdinal(" )")then
3233
letcleanName= nm.[2..nm.Length-3]
3334
cleanName
3435
else nm
3536

3637
/// Returns `true` if given string is an operator display name, e.g. ( |>> )
3738
letIsOperatorName(name:string)=
38-
ifnot(name.StartsWith"("&& name.EndsWith" )")thenfalseelse
39-
letname= name.[2..name.Length-3]
40-
letres= name|> Seq.forall(fun c-> c<>' ')
41-
res
39+
ifnot(name.StartsWithOrdinal("(")&& name.EndsWithOrdinal(" )"))then
40+
false
41+
else
42+
letname= name.[2..name.Length-3]
43+
name|> Seq.forall(fun c-> c<>' ')
4244

4345
if allSuggestions.Contains idTextthen[]else// some other parsing error occurred
4446
allSuggestions
@@ -47,11 +49,11 @@ let FilterPredictions (idText:string) (suggestionF:ErrorLogger.Suggestions) =
4749
// value as well as to formally squelch the associated compiler
4850
// error/warning (FS1182), we remove such names from the suggestions,
4951
// both to prevent accidental usages as well as to encourage good taste
50-
if IsOperatorName suggestion|| suggestion.StartsWith"_"then Noneelse
52+
if IsOperatorName suggestion|| suggestion.StartsWithOrdinal("_")then Noneelse
5153
letsuggestion:string= demangle suggestion
5254
letsuggestedText= suggestion.ToUpperInvariant()
5355
letsimilarity= EditDistance.JaroWinklerDistance uppercaseText suggestedText
54-
if similarity>= highConfidenceThreshold|| suggestion.EndsWith("."+ idText)then
56+
if similarity>= highConfidenceThreshold|| suggestion.EndsWithOrdinal("."+ idText)then
5557
Some(similarity, suggestion)
5658
elif similarity< minThresholdForSuggestions&& suggestedText.Length> minStringLengthForThresholdthen
5759
None

‎src/fsharp/IlxGen.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5281,9 +5281,9 @@ and GenMethodForBinding
52815281

52825282
letmdef=
52835283
if// operator names
5284-
mdef.Name.StartsWith("op_",System.StringComparison.Ordinal)||
5284+
mdef.Name.StartsWithOrdinal("op_")||
52855285
// active pattern names
5286-
mdef.Name.StartsWith("|",System.StringComparison.Ordinal)||
5286+
mdef.Name.StartsWithOrdinal("|")||
52875287
// event add/remove method
52885288
v.val_flags.IsGeneratedEventValthen
52895289
mdef.WithSpecialName

‎src/fsharp/MethodCalls.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,8 @@ let MethInfoChecks g amap isInstance tyargsOpt objArgs ad m (minfo:MethInfo) =
13001300
ifnot(IsTypeAndMethInfoAccessible amap m adOriginal ad minfo)then
13011301
error(Error(FSComp.SR.tcMethodNotAccessible(minfo.LogicalName), m))
13021302

1303-
if isAnyTupleTy g minfo.ApparentEnclosingType&&not minfo.IsExtensionMember&&(minfo.LogicalName.StartsWith"get_Item"|| minfo.LogicalName.StartsWith"get_Rest")then
1303+
if isAnyTupleTy g minfo.ApparentEnclosingType&&not minfo.IsExtensionMember&&
1304+
(minfo.LogicalName.StartsWithOrdinal("get_Item")|| minfo.LogicalName.StartsWithOrdinal("get_Rest"))then
13041305
warning(Error(FSComp.SR.tcTupleMemberNotNormallyUsed(), m))
13051306

13061307
CheckMethInfoAttributes g m tyargsOpt minfo|> CommitOperationResult

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp