Skip to content

Commit a1216fa

Browse files
Separate ZLinq functionality into Open.Text.ZLinq package
- Created new Open.Text.ZLinq package (v10.0.0) for zero-allocation methods - Moved *NoAlloc methods to Source.ZLinq folder - Moved all ZLinq enumerators to StringSegmentSplitEnumerable.cs - Removed ZLinq dependency from main Open.Text package (stays at 10.0.0) - Added Open.Text.ZLinq references to Tests and Benchmarks projects - Updated README with Open.Text.ZLinq documentation section - Updated analyzers to detect ZLinq availability and suggest SplitAsSegmentsNoAlloc - Set RootNamespace to Open.Text for seamless add-on experience Benefits: - Main package stays lean without ZLinq dependency - Users can opt-in to zero-allocation methods by installing Open.Text.ZLinq - Backward compatible - existing Open.Text API unchanged - Analyzers provide smart suggestions based on available packages
1 parent 30a0163 commit a1216fa

34 files changed

Lines changed: 602 additions & 248 deletions

Analyzers/IndexOfSubstringAnalyzer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ private static bool IsIndexOfCall(InvocationExpressionSyntax invocation, SyntaxN
103103
|| containingType?.ToString() == "Microsoft.Extensions.Primitives.StringSegment";
104104
}
105105
}
106+
106107
return false;
107108
}
108109

Analyzers/SplitAnalyzer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ private static bool IsUsedInForeachLoop(SyntaxNode node)
164164
{
165165
return true;
166166
}
167+
167168
parent = parent.Parent;
168169
}
170+
169171
return false;
170172
}
171173

Analyzers/SplitCodeFixProvider.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
5050
equivalenceKey: "UseSplitAsSegments"),
5151
diagnostic);
5252
}
53+
5354
break;
5455
}
5556

@@ -80,6 +81,7 @@ invocation.Expression is MemberAccessExpressionSyntax memberAccess &&
8081
equivalenceKey: "UseFirstSplit"),
8182
diagnostic);
8283
}
84+
8385
break;
8486
}
8587

@@ -96,6 +98,7 @@ invocation.Expression is MemberAccessExpressionSyntax memberAccess &&
9698
equivalenceKey: "UseSplitToEnumerable"),
9799
diagnostic);
98100
}
101+
99102
break;
100103
}
101104
}

Analyzers/StringComparablePatternMatchingSuppressor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public override void ReportSuppressions(SuppressionAnalysisContext context)
7777
break;
7878
}
7979
}
80+
8081
currentNode = currentNode.Parent;
8182
}
8283

@@ -146,6 +147,7 @@ private static bool ContainsStringComparableComparison(SyntaxNode node, Semantic
146147
}
147148
}
148149
}
150+
149151
return false;
150152
}
151153
}

Analyzers/StringConcatenationAnalyzer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ private static bool IsInLoop(SyntaxNode node)
8181
case SyntaxKind.DoStatement:
8282
return true;
8383
}
84+
8485
parent = parent.Parent;
8586
}
87+
8688
return false;
8789
}
8890

Analyzers/TrimEqualsAnalyzer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ private static bool IsTrimCall(InvocationExpressionSyntax invocation, SyntaxNode
114114
return true;
115115
}
116116
}
117+
117118
return false;
118119
}
119120
}

Benchmarks/AllocationBaselineBenchmark.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public int Small_ForeachOnly()
4141
{
4242
count += segment.Length;
4343
}
44+
4445
return count;
4546
}
4647

@@ -53,6 +54,7 @@ public int Small_ForeachWithToString()
5354
var str = segment.ToString();
5455
totalLen += str.Length;
5556
}
57+
5658
return totalLen;
5759
}
5860

@@ -76,6 +78,7 @@ public int Medium_ForeachOnly()
7678
{
7779
count += segment.Length;
7880
}
81+
7982
return count;
8083
}
8184

@@ -101,6 +104,7 @@ public int Large_ForeachOnly()
101104
{
102105
count++;
103106
}
107+
104108
return count;
105109
}
106110

Benchmarks/EnumParseTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public Greek DictionaryLookup()
8383
if (!Lookup(s, out e))
8484
throw new Exception("Invalid.");
8585
}
86+
8687
return e;
8788
}
8889
}
@@ -97,6 +98,7 @@ public override Greek EnumParse()
9798
if (!Enum.TryParse(s, out e))
9899
throw new Exception("Invalid.");
99100
}
101+
100102
return e;
101103
}
102104

@@ -108,6 +110,7 @@ public override Greek CompiledSwitch()
108110
if (!TryParseBySwitch(s, out e))
109111
throw new Exception("Invalid.");
110112
}
113+
111114
return e;
112115
}
113116

@@ -119,6 +122,7 @@ public override Greek CompiledSwitchByLength()
119122
if (!TryParseByLengthSwitch(s, out e))
120123
throw new Exception("Invalid.");
121124
}
125+
122126
return e;
123127
}
124128

@@ -130,6 +134,7 @@ public override Greek EnumValueParse()
130134
if (!EnumValue.TryParse(s, out e))
131135
throw new Exception("Invalid.");
132136
}
137+
133138
return e;
134139
}
135140

@@ -141,6 +146,7 @@ public override Greek FastEnumParse()
141146
if (!FastEnum.TryParse(s, out e))
142147
throw new Exception("Invalid.");
143148
}
149+
144150
return e;
145151
}
146152
}
@@ -155,6 +161,7 @@ public override Greek EnumParse()
155161
if (Enum.TryParse(s, out e))
156162
throw new Exception("Valid.");
157163
}
164+
158165
return e;
159166
}
160167

@@ -166,6 +173,7 @@ public override Greek CompiledSwitch()
166173
if (TryParseBySwitch(s, out e))
167174
throw new Exception("Valid.");
168175
}
176+
169177
return e;
170178
}
171179

@@ -177,6 +185,7 @@ public override Greek CompiledSwitchByLength()
177185
if (TryParseByLengthSwitch(s, out e))
178186
throw new Exception("Valid.");
179187
}
188+
180189
return e;
181190
}
182191

@@ -188,6 +197,7 @@ public override Greek EnumValueParse()
188197
if (EnumValue.TryParse(s, out e))
189198
throw new Exception("Valid.");
190199
}
200+
191201
return e;
192202
}
193203

@@ -199,6 +209,7 @@ public override Greek FastEnumParse()
199209
if (FastEnum.TryParse(s, out e))
200210
throw new Exception("Valid.");
201211
}
212+
202213
return e;
203214
}
204215
}
@@ -213,6 +224,7 @@ public override Greek EnumParse()
213224
if (!Enum.TryParse(s, true, out e))
214225
throw new Exception("Invalid.");
215226
}
227+
216228
return e;
217229
}
218230

@@ -224,6 +236,7 @@ public override Greek CompiledSwitch()
224236
if (!TryParseBySwitchIgnoreCase(s, out e))
225237
throw new Exception("Invalid.");
226238
}
239+
227240
return e;
228241
}
229242

@@ -235,6 +248,7 @@ public override Greek CompiledSwitchByLength()
235248
if (!TryParseByLengthSwitchCaseIgnored(s, out e))
236249
throw new Exception("Invalid.");
237250
}
251+
238252
return e;
239253
}
240254

@@ -246,6 +260,7 @@ public override Greek EnumValueParse()
246260
if (!EnumValue.TryParse(s, true, out e))
247261
throw new Exception("Invalid.");
248262
}
263+
249264
return e;
250265
}
251266

@@ -257,6 +272,7 @@ public override Greek FastEnumParse()
257272
if (!FastEnum.TryParse(s, true, out e))
258273
throw new Exception("Invalid.");
259274
}
275+
260276
return e;
261277
}
262278

@@ -279,6 +295,7 @@ public override Greek EnumParse()
279295
if (Enum.TryParse(s, true, out e))
280296
throw new Exception("Valid.");
281297
}
298+
282299
return e;
283300
}
284301

@@ -290,6 +307,7 @@ public override Greek CompiledSwitch()
290307
if (TryParseBySwitchIgnoreCase(s, out e))
291308
throw new Exception("Valid.");
292309
}
310+
293311
return e;
294312
}
295313

@@ -301,6 +319,7 @@ public override Greek CompiledSwitchByLength()
301319
if (TryParseByLengthSwitchCaseIgnored(s, out e))
302320
throw new Exception("Valid.");
303321
}
322+
304323
return e;
305324
}
306325

@@ -312,6 +331,7 @@ public override Greek EnumValueParse()
312331
if (EnumValue.TryParseIgnoreCase(s, out e))
313332
throw new Exception("Valid.");
314333
}
334+
315335
return e;
316336
}
317337

@@ -323,6 +343,7 @@ public override Greek FastEnumParse()
323343
if (FastEnum.TryParse(s, true, out e))
324344
throw new Exception("Valid.");
325345
}
346+
326347
return e;
327348
}
328349

Benchmarks/Open.Text.Benchmarks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
<ItemGroup>
1919
<ProjectReference Include="..\Source\Open.Text.csproj" />
20+
<ProjectReference Include="..\Source.ZLinq\Open.Text.ZLinq.csproj" />
2021
</ItemGroup>
2122

2223
</Project>

Open.Text.sln

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,101 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1818
.editorconfig = .editorconfig
1919
EndProjectSection
2020
EndProject
21+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source.ZLinq", "Source.ZLinq", "{A0F13297-198D-5842-7C5A-076999C53D0F}"
22+
EndProject
23+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Open.Text.ZLinq", "Source.ZLinq\Open.Text.ZLinq.csproj", "{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}"
24+
EndProject
25+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{B8EFCA5F-814F-285C-A8CB-F00F14650265}"
26+
EndProject
2127
Global
2228
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2329
Debug|Any CPU = Debug|Any CPU
30+
Debug|x64 = Debug|x64
31+
Debug|x86 = Debug|x86
2432
Release|Any CPU = Release|Any CPU
33+
Release|x64 = Release|x64
34+
Release|x86 = Release|x86
2535
EndGlobalSection
2636
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2737
{3C245F69-844A-4DC9-93E7-C02545B013C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2838
{3C245F69-844A-4DC9-93E7-C02545B013C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{3C245F69-844A-4DC9-93E7-C02545B013C0}.Debug|x64.ActiveCfg = Debug|Any CPU
40+
{3C245F69-844A-4DC9-93E7-C02545B013C0}.Debug|x64.Build.0 = Debug|Any CPU
41+
{3C245F69-844A-4DC9-93E7-C02545B013C0}.Debug|x86.ActiveCfg = Debug|Any CPU
42+
{3C245F69-844A-4DC9-93E7-C02545B013C0}.Debug|x86.Build.0 = Debug|Any CPU
2943
{3C245F69-844A-4DC9-93E7-C02545B013C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
3044
{3C245F69-844A-4DC9-93E7-C02545B013C0}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{3C245F69-844A-4DC9-93E7-C02545B013C0}.Release|x64.ActiveCfg = Release|Any CPU
46+
{3C245F69-844A-4DC9-93E7-C02545B013C0}.Release|x64.Build.0 = Release|Any CPU
47+
{3C245F69-844A-4DC9-93E7-C02545B013C0}.Release|x86.ActiveCfg = Release|Any CPU
48+
{3C245F69-844A-4DC9-93E7-C02545B013C0}.Release|x86.Build.0 = Release|Any CPU
3149
{C5BB368A-90CC-4DDA-B587-DAE590308F08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3250
{C5BB368A-90CC-4DDA-B587-DAE590308F08}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{C5BB368A-90CC-4DDA-B587-DAE590308F08}.Debug|x64.ActiveCfg = Debug|Any CPU
52+
{C5BB368A-90CC-4DDA-B587-DAE590308F08}.Debug|x64.Build.0 = Debug|Any CPU
53+
{C5BB368A-90CC-4DDA-B587-DAE590308F08}.Debug|x86.ActiveCfg = Debug|Any CPU
54+
{C5BB368A-90CC-4DDA-B587-DAE590308F08}.Debug|x86.Build.0 = Debug|Any CPU
3355
{C5BB368A-90CC-4DDA-B587-DAE590308F08}.Release|Any CPU.ActiveCfg = Release|Any CPU
3456
{C5BB368A-90CC-4DDA-B587-DAE590308F08}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{C5BB368A-90CC-4DDA-B587-DAE590308F08}.Release|x64.ActiveCfg = Release|Any CPU
58+
{C5BB368A-90CC-4DDA-B587-DAE590308F08}.Release|x64.Build.0 = Release|Any CPU
59+
{C5BB368A-90CC-4DDA-B587-DAE590308F08}.Release|x86.ActiveCfg = Release|Any CPU
60+
{C5BB368A-90CC-4DDA-B587-DAE590308F08}.Release|x86.Build.0 = Release|Any CPU
3561
{CD6319A3-D46A-4764-B4C1-F4C31CCA0EB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3662
{CD6319A3-D46A-4764-B4C1-F4C31CCA0EB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
63+
{CD6319A3-D46A-4764-B4C1-F4C31CCA0EB0}.Debug|x64.ActiveCfg = Debug|Any CPU
64+
{CD6319A3-D46A-4764-B4C1-F4C31CCA0EB0}.Debug|x64.Build.0 = Debug|Any CPU
65+
{CD6319A3-D46A-4764-B4C1-F4C31CCA0EB0}.Debug|x86.ActiveCfg = Debug|Any CPU
66+
{CD6319A3-D46A-4764-B4C1-F4C31CCA0EB0}.Debug|x86.Build.0 = Debug|Any CPU
3767
{CD6319A3-D46A-4764-B4C1-F4C31CCA0EB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
3868
{CD6319A3-D46A-4764-B4C1-F4C31CCA0EB0}.Release|Any CPU.Build.0 = Release|Any CPU
69+
{CD6319A3-D46A-4764-B4C1-F4C31CCA0EB0}.Release|x64.ActiveCfg = Release|Any CPU
70+
{CD6319A3-D46A-4764-B4C1-F4C31CCA0EB0}.Release|x64.Build.0 = Release|Any CPU
71+
{CD6319A3-D46A-4764-B4C1-F4C31CCA0EB0}.Release|x86.ActiveCfg = Release|Any CPU
72+
{CD6319A3-D46A-4764-B4C1-F4C31CCA0EB0}.Release|x86.Build.0 = Release|Any CPU
3973
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4074
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
75+
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Debug|x64.ActiveCfg = Debug|Any CPU
76+
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Debug|x64.Build.0 = Debug|Any CPU
77+
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Debug|x86.ActiveCfg = Debug|Any CPU
78+
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Debug|x86.Build.0 = Debug|Any CPU
4179
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
4280
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Release|Any CPU.Build.0 = Release|Any CPU
81+
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Release|x64.ActiveCfg = Release|Any CPU
82+
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Release|x64.Build.0 = Release|Any CPU
83+
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Release|x86.ActiveCfg = Release|Any CPU
84+
{A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D}.Release|x86.Build.0 = Release|Any CPU
4385
{B2C3D4E5-F6A7-4B5C-9D0E-1F2A3B4C5D6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4486
{B2C3D4E5-F6A7-4B5C-9D0E-1F2A3B4C5D6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
87+
{B2C3D4E5-F6A7-4B5C-9D0E-1F2A3B4C5D6E}.Debug|x64.ActiveCfg = Debug|Any CPU
88+
{B2C3D4E5-F6A7-4B5C-9D0E-1F2A3B4C5D6E}.Debug|x64.Build.0 = Debug|Any CPU
89+
{B2C3D4E5-F6A7-4B5C-9D0E-1F2A3B4C5D6E}.Debug|x86.ActiveCfg = Debug|Any CPU
90+
{B2C3D4E5-F6A7-4B5C-9D0E-1F2A3B4C5D6E}.Debug|x86.Build.0 = Debug|Any CPU
4591
{B2C3D4E5-F6A7-4B5C-9D0E-1F2A3B4C5D6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
4692
{B2C3D4E5-F6A7-4B5C-9D0E-1F2A3B4C5D6E}.Release|Any CPU.Build.0 = Release|Any CPU
93+
{B2C3D4E5-F6A7-4B5C-9D0E-1F2A3B4C5D6E}.Release|x64.ActiveCfg = Release|Any CPU
94+
{B2C3D4E5-F6A7-4B5C-9D0E-1F2A3B4C5D6E}.Release|x64.Build.0 = Release|Any CPU
95+
{B2C3D4E5-F6A7-4B5C-9D0E-1F2A3B4C5D6E}.Release|x86.ActiveCfg = Release|Any CPU
96+
{B2C3D4E5-F6A7-4B5C-9D0E-1F2A3B4C5D6E}.Release|x86.Build.0 = Release|Any CPU
97+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
98+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
99+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}.Debug|x64.ActiveCfg = Debug|Any CPU
100+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}.Debug|x64.Build.0 = Debug|Any CPU
101+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}.Debug|x86.ActiveCfg = Debug|Any CPU
102+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}.Debug|x86.Build.0 = Debug|Any CPU
103+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
104+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}.Release|Any CPU.Build.0 = Release|Any CPU
105+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}.Release|x64.ActiveCfg = Release|Any CPU
106+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}.Release|x64.Build.0 = Release|Any CPU
107+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}.Release|x86.ActiveCfg = Release|Any CPU
108+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA}.Release|x86.Build.0 = Release|Any CPU
47109
EndGlobalSection
48110
GlobalSection(SolutionProperties) = preSolution
49111
HideSolutionNode = FALSE
50112
EndGlobalSection
113+
GlobalSection(NestedProjects) = preSolution
114+
{2F241AF3-5EC7-42CB-9837-EA937BEB97EA} = {A0F13297-198D-5842-7C5A-076999C53D0F}
115+
EndGlobalSection
51116
GlobalSection(ExtensibilityGlobals) = postSolution
52117
SolutionGuid = {E4D180B1-0EE4-4265-B49E-EC5B6A9AFAA3}
53118
EndGlobalSection

0 commit comments

Comments
 (0)