Skip to content

Commit 427f7c9

Browse files
committed
Remove unnecessary null checks
1 parent f938f15 commit 427f7c9

File tree

1 file changed

+19
-41
lines changed

1 file changed

+19
-41
lines changed

SabreTools.Serialization/Wrappers/ISO9660.Printing.cs

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void PrintInformation(StringBuilder builder)
2020
builder.AppendLine("-------------------------");
2121
builder.AppendLine();
2222

23-
if (Model.SystemArea == null || Model.SystemArea.Length == 0)
23+
if (Model.SystemArea.Length == 0)
2424
builder.AppendLine(Model.SystemArea, "System Area");
2525
else if (Array.TrueForAll(Model.SystemArea, b => b == 0))
2626
builder.AppendLine("Zeroed", "System Area");
@@ -38,11 +38,11 @@ public void PrintInformation(StringBuilder builder)
3838

3939
#region Volume Descriptors
4040

41-
protected static void Print(StringBuilder builder, VolumeDescriptor[]? vdSet)
41+
protected static void Print(StringBuilder builder, VolumeDescriptor[] vdSet)
4242
{
4343
builder.AppendLine(" Volume Descriptors:");
4444
builder.AppendLine(" -------------------------");
45-
if (vdSet == null)
45+
if (vdSet.Length == 0)
4646
{
4747
builder.AppendLine(" No volume descriptor set");
4848
builder.AppendLine();
@@ -77,7 +77,7 @@ private static void Print(StringBuilder builder, BootRecordVolumeDescriptor vd)
7777
builder.AppendLine(vd.BootSystemIdentifier, " Boot System Identifier");
7878
builder.AppendLine(vd.BootSystemIdentifier, " Boot Identifier");
7979

80-
if (vd.BootSystemUse == null || vd.BootSystemUse.Length == 0)
80+
if (vd.BootSystemUse.Length == 0)
8181
builder.AppendLine(vd.BootSystemUse, " Boot System Use");
8282
else if (Array.TrueForAll(vd.BootSystemUse, b => b == 0))
8383
builder.AppendLine("Zeroed", " Boot System Use");
@@ -176,14 +176,14 @@ private static void Print(StringBuilder builder, BaseVolumeDescriptor vd)
176176

177177
builder.AppendLine(vd.ReservedByte, " Reserved Byte");
178178

179-
if (vd.ApplicationUse == null || vd.ApplicationUse.Length == 0)
179+
if (vd.ApplicationUse.Length == 0)
180180
builder.AppendLine(vd.ApplicationUse, " Application Use");
181181
else if (Array.TrueForAll(vd.ApplicationUse, b => b == 0))
182182
builder.AppendLine("Zeroed", " Application Use");
183183
else
184184
builder.AppendLine("Not Zeroed", " Application Use");
185185

186-
if (vd.Reserved653Bytes == null || vd.Reserved653Bytes.Length == 0)
186+
if (vd.Reserved653Bytes.Length == 0)
187187
builder.AppendLine(vd.Reserved653Bytes, " Reserved 653 Bytes");
188188
else if (Array.TrueForAll(vd.Reserved653Bytes, b => b == 0))
189189
builder.AppendLine("Zeroed", " Reserved 653 Bytes");
@@ -203,7 +203,7 @@ private static void Print(StringBuilder builder, VolumePartitionDescriptor vd)
203203
builder.AppendLineBothEndian(vd.VolumePartitionLocation, " Volume Partition Location");
204204
builder.AppendLineBothEndian(vd.VolumePartitionSize, " Volume Partition Size");
205205

206-
if (vd.SystemUse == null || vd.SystemUse.Length == 0)
206+
if (vd.SystemUse.Length == 0)
207207
builder.AppendLine(vd.SystemUse, " System Use");
208208
else if (Array.TrueForAll(vd.SystemUse, b => b == 0))
209209
builder.AppendLine("Zeroed", " System Use");
@@ -218,7 +218,7 @@ private static void Print(StringBuilder builder, VolumeDescriptorSetTerminator v
218218
builder.AppendLine(" Volume Descriptor Set Terminator:");
219219
builder.AppendLine(" -------------------------");
220220

221-
if (vd.Reserved2041Bytes == null || vd.Reserved2041Bytes.Length == 0)
221+
if (vd.Reserved2041Bytes.Length == 0)
222222
builder.AppendLine(vd.Reserved2041Bytes, " Reserved Bytes");
223223
else if (Array.TrueForAll(vd.Reserved2041Bytes, b => b == 0))
224224
builder.AppendLine("Zeroed", " Reserved Bytes");
@@ -233,7 +233,7 @@ private static void Print(StringBuilder builder, GenericVolumeDescriptor vd)
233233
builder.AppendLine(" Unidentified Volume Descriptor:");
234234
builder.AppendLine(" -------------------------");
235235

236-
if (vd.Data == null || vd.Data.Length == 0)
236+
if (vd.Data.Length == 0)
237237
builder.AppendLine(vd.Data, " Data");
238238
else if (Array.TrueForAll(vd.Data, b => b == 0))
239239
builder.AppendLine("Zeroed", " Data");
@@ -247,11 +247,11 @@ private static void Print(StringBuilder builder, GenericVolumeDescriptor vd)
247247

248248
#region Path Tables
249249

250-
protected static void Print(StringBuilder builder, PathTableGroup[]? ptgs, Encoding encoding)
250+
protected static void Print(StringBuilder builder, PathTableGroup[] ptgs, Encoding encoding)
251251
{
252252
builder.AppendLine(" Path Table Group(s):");
253253
builder.AppendLine(" -------------------------");
254-
if (ptgs == null)
254+
if (ptgs.Length == 0)
255255
{
256256
builder.AppendLine(" No path table groups");
257257
builder.AppendLine();
@@ -336,11 +336,11 @@ private static void Print(StringBuilder builder, PathTableRecord[]? records, Enc
336336

337337
#region Directories
338338

339-
protected static void Print(StringBuilder builder, Dictionary<int, FileExtent>? dirs, Encoding encoding)
339+
protected static void Print(StringBuilder builder, Dictionary<int, FileExtent> dirs, Encoding encoding)
340340
{
341341
builder.AppendLine(" Directory Descriptors Information:");
342342
builder.AppendLine(" -------------------------");
343-
if (dirs == null)
343+
if (dirs.Count == 0)
344344
{
345345
builder.AppendLine(" No directory descriptors");
346346
builder.AppendLine();
@@ -355,18 +355,11 @@ protected static void Print(StringBuilder builder, Dictionary<int, FileExtent>?
355355
}
356356
}
357357

358-
private static void Print(StringBuilder builder, FileExtent? extent, Encoding encoding)
358+
private static void Print(StringBuilder builder, FileExtent extent, Encoding encoding)
359359
{
360-
if (extent == null)
361-
{
362-
builder.AppendLine(" No directory descriptor");
363-
builder.AppendLine();
364-
return;
365-
}
366-
367360
if (extent is DirectoryExtent dir)
368361
{
369-
if (dir.DirectoryRecords == null)
362+
if (dir.DirectoryRecords.Length == 0)
370363
{
371364
builder.AppendLine(" No directory records");
372365
builder.AppendLine();
@@ -391,15 +384,8 @@ private static void Print(StringBuilder builder, FileExtent? extent, Encoding en
391384
builder.AppendLine();
392385
}
393386

394-
private static void Print(StringBuilder builder, DirectoryRecord? dr, Encoding encoding)
387+
private static void Print(StringBuilder builder, DirectoryRecord dr, Encoding encoding)
395388
{
396-
if (dr == null)
397-
{
398-
builder.AppendLine(" No directory record");
399-
builder.AppendLine();
400-
return;
401-
}
402-
403389
builder.AppendLine(dr.DirectoryRecordLength, " Directory Record Length");
404390
builder.AppendLine(dr.ExtendedAttributeRecordLength, " Extended Attribute Record Length");
405391

@@ -427,21 +413,16 @@ private static void Print(StringBuilder builder, DirectoryRecord? dr, Encoding e
427413
builder.AppendLine(dr.FileIdentifier, " File Identifier");
428414
builder.AppendLine(dr.PaddingField, " Padding Field");
429415

430-
if (dr.SystemUse == null || dr.SystemUse.Length == 0)
416+
if (dr.SystemUse.Length == 0)
431417
builder.AppendLine(dr.SystemUse, " System Use");
432418
else if (Array.TrueForAll(dr.SystemUse, b => b == 0))
433419
builder.AppendLine($"Zeroed ({dr.SystemUse.Length} bytes)", " System Use");
434420
else
435421
builder.AppendLine($"Not Zeroed ({dr.SystemUse.Length} bytes)", " System Use");
436422
}
437423

438-
private static void Print(StringBuilder builder, DirectoryRecordDateTime? drdt)
424+
private static void Print(StringBuilder builder, DirectoryRecordDateTime drdt)
439425
{
440-
if (drdt == null)
441-
{
442-
builder.AppendLine("[NULL]", " Directory Record Date Time");
443-
return;
444-
}
445426
builder.AppendLine(" Directory Record Date Time:");
446427

447428
builder.AppendLine(drdt.YearsSince1990, " Years Since 1900");
@@ -498,11 +479,8 @@ private static void Print(StringBuilder builder, ExtendedAttributeRecord? ear, E
498479

499480
#endregion
500481

501-
private static string? Format(DecDateTime? dt)
482+
private static string Format(DecDateTime dt)
502483
{
503-
if (dt == null)
504-
return null;
505-
506484
string year = dt.Year.IsNumericArray()
507485
? Encoding.ASCII.GetString(dt.Year)
508486
: BitConverter.ToString(dt.Year).Replace('-', ' ');

0 commit comments

Comments
 (0)