Skip to content

Commit

Permalink
Remove some dead code / branches
Browse files Browse the repository at this point in the history
Some signal amidst the noise in an lgtm.com report.
  • Loading branch information
stephentoub committed Jun 2, 2022
1 parent 655bc1d commit 2826415
Show file tree
Hide file tree
Showing 31 changed files with 68 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,7 @@ private bool GetResultOfBind()

// Record our best match in the memgroup as well. This is temporary.

if (true)
{
ReportErrorsOnSuccess();
}
ReportErrorsOnSuccess();

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1576,11 +1576,9 @@ private static void NodeRemove(object key, TypeDescriptionProvider provider)
{
TypeDescriptionNode? head = (TypeDescriptionNode?)s_providerTable[key];
TypeDescriptionNode? target = head;
TypeDescriptionNode? prev = null;

while (target != null && target.Provider != provider)
{
prev = target;
target = target.Next;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2833,7 +2833,7 @@ SqlDecimal snumOp

private static void CheckValidPrecScale(byte bPrec, byte bScale)
{
if (bPrec < 1 || bPrec > MaxPrecision || bScale < 0 || bScale > MaxScale || bScale > bPrec)
if (bPrec < 1 || bPrec > MaxPrecision || bScale > MaxScale || bScale > bPrec)
throw new SqlTypeException(SQLResource.InvalidPrecScaleMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,17 +557,13 @@ internal void DestroyObject(DbConnectionInternal obj)
// we simply leave it alone; when the transaction completes, it will
// come back through PutObjectFromTransactedPool, which will call us
// again.
bool removed = false;
lock (_objectList)
{
removed = _objectList.Remove(obj);
bool removed = _objectList.Remove(obj);
Debug.Assert(removed, "attempt to DestroyObject not in list");
_totalObjects = _objectList.Count;
}

if (removed)
{
}
obj.Dispose();
}

Expand Down Expand Up @@ -932,9 +928,6 @@ private void PrepareConnection(DbConnection owningObject, DbConnectionInternal o
// following assert to fire, which really mucks up stress against
// checked bits.

if (null != obj)
{
}
return (obj);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void OnEventCommand(EventCommandEventArgs command)

double defaultIntervalSecs = 1;
Debug.Assert(AggregationManager.MinCollectionTimeSecs <= defaultIntervalSecs);
double refreshIntervalSecs = defaultIntervalSecs;
double refreshIntervalSecs;
if (command.Arguments!.TryGetValue("RefreshInterval", out string? refreshInterval))
{
Log.Message($"RefreshInterval argument received: {refreshInterval}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ private FileVersionInfo(string fileName)
// that this should match for all intents and purposes. If this ever becomes a problem,
// we can implement a full-fledged Win32 resource parser; that would also enable support
// for native Win32 PE files on Unix, but that should also be an extremely rare case.
if (!TryLoadManagedAssemblyMetadata())
{
// We could try to parse Executable and Linkable Format (ELF) files, but at present
// for executables they don't store version information, which is typically just
// available in the filename itself. For now, we won't do anything special, but
// we can add more cases here as we find need and opportunity.
}
TryLoadManagedAssemblyMetadata();

// If TryLoadManagedAssemblyMetadata returns false, we could try to parse Executable and Linkable
// Format (ELF) files, but at present for executables they don't store version information, which
// is typically just available in the filename itself. For now, we won't do anything special, but
// we can add more cases here as we find need and opportunity.
}

/// <summary>Attempt to load our fields from the metadata of the file, if it's a managed assembly.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ private bool WriteLocalFileHeader(bool isEmptyFile)
{
// if we have a non-seekable stream, don't worry about sizes at all, and just set the right bit
// if we are using the data descriptor, then sizes and crc should be set to 0 in the header
if (_archive.Mode == ZipArchiveMode.Create && _archive.ArchiveStream.CanSeek == false && !isEmptyFile)
if (_archive.Mode == ZipArchiveMode.Create && _archive.ArchiveStream.CanSeek == false)
{
_generalPurposeBitFlag |= BitFlagValues.DataDescriptor;
zip64Used = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,6 @@ private void ProcessEvents()
}

uint mask = nextEvent.mask;
ReadOnlySpan<char> expandedName = ReadOnlySpan<char>.Empty;
WatchedDirectory? associatedDirectoryEntry = null;

// An overflow event means that we can't trust our state without restarting since we missed events and
// some of those events could be a directory create, meaning we wouldn't have added the directory to the
Expand All @@ -585,24 +583,24 @@ private void ProcessEvents()
}
break;
}
else

// Look up the directory information for the supplied wd
WatchedDirectory? associatedDirectoryEntry = null;
lock (SyncObj)
{
// Look up the directory information for the supplied wd
lock (SyncObj)
if (!_wdToPathMap.TryGetValue(nextEvent.wd, out associatedDirectoryEntry))
{
if (!_wdToPathMap.TryGetValue(nextEvent.wd, out associatedDirectoryEntry))
{
// The watch descriptor could be missing from our dictionary if it was removed
// due to cancellation, or if we already removed it and this is a related event
// like IN_IGNORED. In any case, just ignore it... even if for some reason we
// should have the value, there's little we can do about it at this point,
// and there's no more processing of this event we can do without it.
continue;
}
// The watch descriptor could be missing from our dictionary if it was removed
// due to cancellation, or if we already removed it and this is a related event
// like IN_IGNORED. In any case, just ignore it... even if for some reason we
// should have the value, there's little we can do about it at this point,
// and there's no more processing of this event we can do without it.
continue;
}
expandedName = associatedDirectoryEntry.GetPath(true, nextEvent.name);
}

ReadOnlySpan<char> expandedName = associatedDirectoryEntry.GetPath(true, nextEvent.name);

// To match Windows, ignore all changes that happen on the root folder itself
if (expandedName.IsEmpty)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,30 +209,15 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
if (_contentTypeHelper != null)
{
_contentTypeHelper.SaveToFile();
}

if (_zipStreamManager != null)
{
_zipStreamManager.Dispose();
}

if (_zipArchive != null)
{
_zipArchive.Dispose();
}
_contentTypeHelper?.SaveToFile();
_zipArchive?.Dispose();

// _containerStream may be opened given a file name, in which case it should be closed here.
// _containerStream may be passed into the constructor, in which case, it should not be closed here.
if (_shouldCloseContainerStream)
{
_containerStream.Dispose();
}
else
{
}
_containerStream = null!;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

namespace System.IO.Packaging
{
internal sealed class ZipStreamManager : IDisposable
internal sealed class ZipStreamManager
{
private readonly ZipArchive _zipArchive;
private readonly FileAccess _packageFileAccess;
private readonly FileMode _packageFileMode;
private bool _disposed;

public ZipStreamManager(ZipArchive zipArchive, FileMode packageFileMode, FileAccess packageFileAccess)
{
Expand Down Expand Up @@ -85,27 +84,5 @@ public Stream Open(ZipArchiveEntry zipArchiveEntry, FileMode streamFileMode, Fil
Stream ns = zipArchiveEntry.Open();
return new ZipWrappingStream(zipArchiveEntry, ns, _packageFileMode, _packageFileAccess, canRead, canWrite);
}

//
// IDisposable interface
//
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

// Protected implementation of Dispose pattern.
private void Dispose(bool disposing)
{
if (_disposed)
return;

if (disposing)
{
}

_disposed = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ private enum Flow
private readonly TextWriter _out;
private int _column;

private readonly Stack<int> _stack = new Stack<int>();
private int _delta;
private int _depth;
private Flow _flow;

// All the unique lambda expressions in the ET, will be used for displaying all
Expand All @@ -57,20 +56,16 @@ private DebugViewWriter(TextWriter file)
_out = file;
}

private int Base => _stack.Count > 0 ? _stack.Peek() : 0;

private int Delta => _delta;

private int Depth => Base + Delta;
private int Depth => _depth;

private void Indent()
{
_delta += Tab;
_depth += Tab;
}

private void Dedent()
{
_delta -= Tab;
_depth -= Tab;
}

private void NewLine()
Expand Down Expand Up @@ -137,7 +132,6 @@ private void WriteTo(Expression node)
else
{
Visit(node);
Debug.Assert(_stack.Count == 0);
}

//
Expand Down Expand Up @@ -1185,7 +1179,6 @@ private void WriteLambda(LambdaExpression lambda)
Visit(lambda.Body);
Dedent();
Out(Flow.NewLine, "}");
Debug.Assert(_stack.Count == 0);
}

private string GetLambdaName(LambdaExpression lambda)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void Start()

public void Start(int backlog)
{
if (backlog > (int)SocketOptionName.MaxConnections || backlog < 0)
if (backlog < 0)
{
throw new ArgumentOutOfRangeException(nameof(backlog));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2955,9 +2955,6 @@ private static bool AdjustTimeZoneToLocal(ref DateTimeResult result, bool bTimeO
//
private static bool ParseISO8601(ref DateTimeRawInfo raw, ref __DTString str, DateTimeStyles styles, ref DateTimeResult result)
{
if (raw.year < 0 || raw.GetNumber(0) < 0 || raw.GetNumber(1) < 0)
{
}
str.Index--;
int second = 0;
double partSecond = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,28 +657,15 @@ internal sealed override OperationStatus DecodeFirstRune(ReadOnlySpan<byte> byte
{
if (!bytes.IsEmpty)
{
// Latin-1 byte
byte b = bytes[0];
if (b <= byte.MaxValue)
{
// Latin-1 byte

value = new Rune(b);
bytesConsumed = 1;
return OperationStatus.Done;
}
else
{
// Non-Latin-1 byte

value = Rune.ReplacementChar;
bytesConsumed = 1;
return OperationStatus.InvalidData;
}
value = new Rune(b);
bytesConsumed = 1;
return OperationStatus.Done;
}
else
{
// No data to decode

value = Rune.ReplacementChar;
bytesConsumed = 0;
return OperationStatus.NeedMoreData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1101,10 +1101,7 @@ public override int GetMaxCharCount(int byteCount)
charCount /= 2;
}

if (charCount > 0x7fffffff)
throw new ArgumentOutOfRangeException(nameof(byteCount), SR.ArgumentOutOfRange_GetCharCountOverflow);

return (int)charCount;
return charCount;
}

public override byte[] GetPreamble()
Expand Down
5 changes: 1 addition & 4 deletions src/libraries/System.Private.Uri/src/System/Uri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2690,10 +2690,7 @@ private string ReCreateParts(UriComponents parts, ushort nonCanonical, UriFormat
}
else
{
if (InFact(Flags.E_UserNotCanonical))
{
// We should throw here but currently just accept user input known as invalid
}
// We would ideally throw here if InFact(Flags.E_UserNotCanonical) but currently just accept user input known as invalid
dest.Append(slice);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3791,10 +3791,7 @@ private bool ParseXmlDeclaration(bool isTextDecl)
if (XmlConvert.StrEqual(_ps.chars, _ps.charPos, nameEndPos - _ps.charPos, "standalone") &&
(xmlDeclState == 1 || xmlDeclState == 2) && !isTextDecl)
{
if (!isTextDecl)
{
attr = AddAttributeNoChecks("standalone", 1);
}
attr = AddAttributeNoChecks("standalone", 1);
xmlDeclState = 2;
break;
}
Expand Down Expand Up @@ -6168,7 +6165,7 @@ private EntityType HandleGeneralEntityReference(string name, bool isInAttributeV
{
PushExternalEntity(entity);
_curNode.entityId = _ps.entityId;
return (isInAttributeValue && _validatingReaderCompatFlag) ? EntityType.ExpandedInAttribute : EntityType.Expanded;
return EntityType.Expanded;
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1349,10 +1349,7 @@ private async Task<bool> ParseXmlDeclarationAsync(bool isTextDecl)
if (XmlConvert.StrEqual(_ps.chars, _ps.charPos, nameEndPos - _ps.charPos, "standalone") &&
(xmlDeclState == 1 || xmlDeclState == 2) && !isTextDecl)
{
if (!isTextDecl)
{
attr = AddAttributeNoChecks("standalone", 1);
}
attr = AddAttributeNoChecks("standalone", 1);
xmlDeclState = 2;
break;
}
Expand Down Expand Up @@ -3926,7 +3923,7 @@ private async Task<EntityType> HandleGeneralEntityReferenceAsync(string name, bo
{
await PushExternalEntityAsync(entity).ConfigureAwait(false);
_curNode.entityId = _ps.entityId;
return (isInAttributeValue && _validatingReaderCompatFlag) ? EntityType.ExpandedInAttribute : EntityType.Expanded;
return EntityType.Expanded;
}
}
else
Expand Down
Loading

0 comments on commit 2826415

Please sign in to comment.