Skip to content

Commit 47560bc

Browse files
committed
Apply CA1859: Change type of field from INullValueDictionary to NullValueDictionary for improved performance
1 parent 558c830 commit 47560bc

File tree

18 files changed

+1482
-1306
lines changed

18 files changed

+1482
-1306
lines changed

src/iTextSharp.LGPLv2.Core/System/util/Properties.cs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ public virtual string this[string key]
2626
set => _col[key] = value;
2727
}
2828

29-
public virtual void Add(string key, string value)
30-
{
31-
_col[key] = value;
32-
}
29+
public virtual void Add(string key, string value) => _col[key] = value;
3330

3431
public void AddAll(Properties col)
3532
{
@@ -44,22 +41,21 @@ public void AddAll(Properties col)
4441
}
4542
}
4643

47-
public void Clear()
48-
{
49-
_col.Clear();
50-
}
44+
public void Clear() => _col.Clear();
5145

5246
public bool ContainsKey(string key) => _col.ContainsKey(key);
5347

5448
public IEnumerator<KeyValuePair<string, string>> GetEnumerator() => _col.GetEnumerator();
5549

5650
public void Load(Stream inStream)
5751
{
58-
using var inp = new StreamReader(inStream, EncodingsRegistry.GetEncoding(1252));
52+
using var inp = new StreamReader(inStream, EncodingsRegistry.GetEncoding(codepage: 1252));
53+
5954
while (true)
6055
{
6156
// Get next line
6257
var line = inp.ReadLine();
58+
6359
if (line == null)
6460
{
6561
return;
@@ -70,6 +66,7 @@ public void Load(Stream inStream)
7066
// Find start of key
7167
var len = line.Length;
7268
int keyStart;
69+
7370
for (keyStart = 0; keyStart < len; keyStart++)
7471
{
7572
if (WhiteSpaceChars.IndexOf(line[keyStart].ToString(), StringComparison.Ordinal) == -1)
@@ -86,19 +83,23 @@ public void Load(Stream inStream)
8683

8784
// Continue lines that end in slashes if they are not comments
8885
var firstChar = line[keyStart];
86+
8987
if (firstChar != '#' && firstChar != '!')
9088
{
9189
while (continueLine(line))
9290
{
9391
var nextLine = inp.ReadLine();
92+
9493
if (nextLine == null)
9594
{
9695
nextLine = "";
9796
}
9897

99-
var loppedLine = line.Substring(0, len - 1);
98+
var loppedLine = line.Substring(startIndex: 0, len - 1);
99+
100100
// Advance beyond whitespace on new line
101101
int startIndex;
102+
102103
for (startIndex = 0; startIndex < nextLine.Length; startIndex++)
103104
{
104105
if (WhiteSpaceChars.IndexOf(nextLine[startIndex].ToString(), StringComparison.Ordinal) ==
@@ -108,16 +109,18 @@ public void Load(Stream inStream)
108109
}
109110
}
110111

111-
nextLine = nextLine.Substring(startIndex, nextLine.Length - startIndex);
112+
nextLine = nextLine.Substring(startIndex);
112113
line = loppedLine + nextLine;
113114
len = line.Length;
114115
}
115116

116117
// Find separation between key and value
117118
int separatorIndex;
119+
118120
for (separatorIndex = keyStart; separatorIndex < len; separatorIndex++)
119121
{
120122
var currentChar = line[separatorIndex];
123+
121124
if (currentChar == '\\')
122125
{
123126
separatorIndex++;
@@ -130,6 +133,7 @@ public void Load(Stream inStream)
130133

131134
// Skip over whitespace after key if any
132135
int valueIndex;
136+
133137
for (valueIndex = separatorIndex; valueIndex < len; valueIndex++)
134138
{
135139
if (WhiteSpaceChars.IndexOf(line[valueIndex].ToString(), StringComparison.Ordinal) == -1)
@@ -175,13 +179,15 @@ public string Remove(string key)
175179
{
176180
var retval = _col[key];
177181
_col.Remove(key);
182+
178183
return retval;
179184
}
180185

181186
private static bool continueLine(string line)
182187
{
183188
var slashCount = 0;
184189
var index = line.Length - 1;
190+
185191
while (index >= 0 && line[index--] == '\\')
186192
{
187193
slashCount++;
@@ -203,16 +209,20 @@ private static string loadConvert(string theString)
203209
for (var x = 0; x < len;)
204210
{
205211
aChar = theString[x++];
212+
206213
if (aChar == '\\')
207214
{
208215
aChar = theString[x++];
216+
209217
if (aChar == 'u')
210218
{
211219
// Read the xxxx
212220
var value = 0;
221+
213222
for (var i = 0; i < 4; i++)
214223
{
215224
aChar = theString[x++];
225+
216226
switch (aChar)
217227
{
218228
case '0':
@@ -226,6 +236,7 @@ private static string loadConvert(string theString)
226236
case '8':
227237
case '9':
228238
value = (value << 4) + aChar - '0';
239+
229240
break;
230241
case 'a':
231242
case 'b':
@@ -234,6 +245,7 @@ private static string loadConvert(string theString)
234245
case 'e':
235246
case 'f':
236247
value = (value << 4) + 10 + aChar - 'a';
248+
237249
break;
238250
case 'A':
239251
case 'B':
@@ -242,10 +254,10 @@ private static string loadConvert(string theString)
242254
case 'E':
243255
case 'F':
244256
value = (value << 4) + 10 + aChar - 'A';
257+
245258
break;
246259
default:
247-
throw new ArgumentException(
248-
"Malformed \\uxxxx encoding.");
260+
throw new ArgumentException(message: "Malformed \\uxxxx encoding.");
249261
}
250262
}
251263

src/iTextSharp.LGPLv2.Core/iTextSharp/text/html/simpleparser/IncTable.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace iTextSharp.text.html.simpleparser;
88
/// </summary>
99
public class IncTable : IElement
1010
{
11-
private readonly INullValueDictionary<string, string> _props = new NullValueDictionary<string, string>();
11+
private readonly NullValueDictionary<string, string> _props = new();
1212
private List<PdfPCell> _cols;
1313

1414
/// <summary>
@@ -65,23 +65,26 @@ public PdfPTable BuildTable()
6565
{
6666
if (Rows.Count == 0)
6767
{
68-
return new PdfPTable(1);
68+
return new PdfPTable(numColumns: 1);
6969
}
7070

7171
var ncol = 0;
7272

73-
var c0 = Rows[0];
73+
var c0 = Rows[index: 0];
74+
7475
for (var k = 0; k < c0.Count; ++k)
7576
{
7677
ncol += c0[k].Colspan;
7778
}
7879

7980
var table = new PdfPTable(ncol);
8081

81-
var widths = _props["widths"];
82+
var widths = _props[key: "widths"];
83+
8284
if (widths != null)
8385
{
8486
var intWidths = new List<int>();
87+
8588
foreach (var widthElement in widths.Split(','))
8689
{
8790
intWidths.Add(int.Parse(widthElement, CultureInfo.InvariantCulture));
@@ -90,17 +93,18 @@ public PdfPTable BuildTable()
9093
table.SetWidths(intWidths.ToArray());
9194
}
9295

93-
var width = _props["width"];
96+
var width = _props[key: "width"];
97+
9498
if (width == null)
9599
{
96100
table.WidthPercentage = 100;
97101
}
98102
else
99103
{
100-
if (width.EndsWith("%", StringComparison.OrdinalIgnoreCase))
104+
if (width.EndsWith(value: "%", StringComparison.OrdinalIgnoreCase))
101105
{
102-
table.WidthPercentage =
103-
float.Parse(width.Substring(0, width.Length - 1), NumberFormatInfo.InvariantInfo);
106+
table.WidthPercentage = float.Parse(width.Substring(startIndex: 0, width.Length - 1),
107+
NumberFormatInfo.InvariantInfo);
104108
}
105109
else
106110
{
@@ -112,6 +116,7 @@ public PdfPTable BuildTable()
112116
for (var row = 0; row < Rows.Count; ++row)
113117
{
114118
var col = Rows[row];
119+
115120
for (var k = 0; k < col.Count; ++k)
116121
{
117122
table.AddCell(col[k]);

0 commit comments

Comments
 (0)