Skip to content

Commit

Permalink
Merge pull request #20846 from CyrusNajmabadi/useDefault
Browse files Browse the repository at this point in the history
Use simple default expressions
  • Loading branch information
CyrusNajmabadi authored Jul 13, 2017
2 parents 333eabc + 7c2f466 commit 878ffad
Show file tree
Hide file tree
Showing 373 changed files with 1,113 additions and 1,113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static ImmutableArray<T> AsImmutableOrNull<T>(this IEnumerable<T> items)
{
if (items == null)
{
return default(ImmutableArray<T>);
return default;
}

return ImmutableArray.CreateRange<T>(items);
Expand Down Expand Up @@ -86,7 +86,7 @@ public static ImmutableArray<T> AsImmutableOrNull<T>(this T[] items)
{
if (items == null)
{
return default(ImmutableArray<T>);
return default;
}

return ImmutableArray.Create<T>(items);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static AssemblyIdentity TryGetAssemblyIdentity(string filePath)
BlobHandle publicKeyHandle = assemblyDefinition.PublicKey;
ImmutableArray<byte> publicKeyOrToken = !publicKeyHandle.IsNil
? metadataReader.GetBlobBytes(publicKeyHandle).AsImmutableOrNull()
: default(ImmutableArray<byte>);
: default;
return new AssemblyIdentity(name, version, cultureName, publicKeyOrToken, hasPublicKey);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public bool UnsafeTryGetValue(K key, out V value)
}
else
{
value = default(V);
value = default;
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Compilers/Core/Portable/InternalUtilities/ConsList`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal struct Enumerator : IEnumerator<T>

internal Enumerator(ConsList<T> list)
{
_current = default(T);
_current = default;
_tail = list;
}

Expand All @@ -50,7 +50,7 @@ public bool MoveNext()
return true;
}

_current = default(T);
_current = default;
return false;
}

Expand All @@ -74,7 +74,7 @@ public void Reset()

private ConsList()
{
_head = default(T);
_head = default;
_tail = null;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Compilers/Core/Portable/InternalUtilities/MultiDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public Enumerator(ValueSet v)
{
if (v._value == null)
{
_value = default(V);
_values = default(ImmutableHashSet<V>.Enumerator);
_value = default;
_values = default;
_count = 0;
}
else
Expand All @@ -33,12 +33,12 @@ public Enumerator(ValueSet v)
if (set == null)
{
_value = (V)v._value;
_values = default(ImmutableHashSet<V>.Enumerator);
_values = default;
_count = 1;
}
else
{
_value = default(V);
_value = default;
_values = set.GetEnumerator();
_count = set.Count;
Debug.Assert(_count > 1);
Expand Down Expand Up @@ -177,7 +177,7 @@ public ValueSet this[K k]
{
get
{
return _dictionary.TryGetValue(k, out var set) ? set : default(ValueSet);
return _dictionary.TryGetValue(k, out var set) ? set : default;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Compilers/Core/Portable/InternalUtilities/OneOrMany.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal struct OneOrMany<T>
public OneOrMany(T one)
{
_one = one;
_many = default(ImmutableArray<T>);
_many = default;
}

public OneOrMany(ImmutableArray<T> many)
Expand All @@ -32,7 +32,7 @@ public OneOrMany(ImmutableArray<T> many)
throw new ArgumentNullException(nameof(many));
}

_one = default(T);
_one = default;
_many = many;
}

Expand Down Expand Up @@ -103,7 +103,7 @@ public OneOrMany<T> RemoveAll(T item)
{
if (_many.IsDefault)
{
return item.Equals(_one) ? default(OneOrMany<T>) : this;
return item.Equals(_one) ? default : this;
}

var builder = ArrayBuilder<T>.GetInstance();
Expand All @@ -118,7 +118,7 @@ public OneOrMany<T> RemoveAll(T item)

if (builder.Count == 0)
{
return default(OneOrMany<T>);
return default;
}

return builder.Count == Count ? this : new OneOrMany<T>(builder.ToImmutableAndFree());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static T CreateDelegate<T>(this MethodInfo methodInfo)
{
if (methodInfo == null)
{
return default(T);
return default;
}

return (T)(object)methodInfo.CreateDelegate(typeof(T));
Expand All @@ -115,7 +115,7 @@ public static T InvokeConstructor<T>(this ConstructorInfo constructorInfo, param
{
if (constructorInfo == null)
{
return default(T);
return default;
}

try
Expand All @@ -126,7 +126,7 @@ public static T InvokeConstructor<T>(this ConstructorInfo constructorInfo, param
{
ExceptionDispatchInfo.Capture(e.InnerException).Throw();
Debug.Assert(false, "Unreachable");
return default(T);
return default;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace Roslyn.Utilities
{
internal static class SemaphoreSlimExtensions
{
public static SemaphoreDisposer DisposableWait(this SemaphoreSlim semaphore, CancellationToken cancellationToken = default(CancellationToken))
public static SemaphoreDisposer DisposableWait(this SemaphoreSlim semaphore, CancellationToken cancellationToken = default)
{
semaphore.Wait(cancellationToken);
return new SemaphoreDisposer(semaphore);
}

public async static Task<SemaphoreDisposer> DisposableWaitAsync(this SemaphoreSlim semaphore, CancellationToken cancellationToken = default(CancellationToken))
public async static Task<SemaphoreDisposer> DisposableWaitAsync(this SemaphoreSlim semaphore, CancellationToken cancellationToken = default)
{
await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
return new SemaphoreDisposer(semaphore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public bool Remove(TKey key)

public bool TryGetValue(TKey key, out TValue value)
{
value = default(TValue);
value = default;
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/Core/Portable/Serialization/ObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private ObjectReader(
/// </summary>
public static ObjectReader TryGetReader(
Stream stream,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (stream == null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/Core/Portable/Serialization/ObjectWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal sealed partial class ObjectWriter : IDisposable
/// <param name="cancellationToken"></param>
public ObjectWriter(
Stream stream,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
// String serialization assumes both reader and writer to be of the same endianness.
// It can be adjusted for BigEndian if needed.
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/Core/Portable/Syntax/SyntaxTreeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private static int FindFirstDifference(string s1, string s2)
/// <summary>
/// Returns <c>true</c> if the provided position is in a hidden region inaccessible to the user.
/// </summary>
public static bool IsHiddenPosition(this SyntaxTree tree, int position, CancellationToken cancellationToken = default(CancellationToken))
public static bool IsHiddenPosition(this SyntaxTree tree, int position, CancellationToken cancellationToken = default)
{
if (!tree.HasHiddenRegions())
{
Expand Down
16 changes: 8 additions & 8 deletions src/Dependencies/CodeAnalysis.Debugging/CustomDebugInfoReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static ImmutableArray<byte> TryGetCustomDebugInfoRecord(byte[] customDebu
}
}

return default(ImmutableArray<byte>);
return default;
}

/// <remarks>
Expand Down Expand Up @@ -349,16 +349,16 @@ public static ImmutableArray<ImmutableArray<string>> GetCSharpGroupedImportStrin
Func<int, TArg, ImmutableArray<string>> getMethodImportStrings,
out ImmutableArray<string> externAliasStrings)
{
externAliasStrings = default(ImmutableArray<string>);
externAliasStrings = default;

ImmutableArray<short> groupSizes = default(ImmutableArray<short>);
ImmutableArray<short> groupSizes = default;
bool seenForward = false;

RETRY:
byte[] bytes = getMethodCustomDebugInfo(methodToken, arg);
if (bytes == null)
{
return default(ImmutableArray<ImmutableArray<string>>);
return default;
}

foreach (var record in GetCustomDebugInfoRecords(bytes))
Expand Down Expand Up @@ -421,7 +421,7 @@ public static ImmutableArray<ImmutableArray<string>> GetCSharpGroupedImportStrin
if (groupSizes.IsDefault)
{
// This can happen in malformed PDBs (e.g. chains of forwards).
return default(ImmutableArray<ImmutableArray<string>>);
return default;
}

ImmutableArray<string> importStrings = getMethodImportStrings(methodToken, arg);
Expand Down Expand Up @@ -593,7 +593,7 @@ public static bool TryParseCSharpImportString(string import, out string alias, o
alias = null;
externAlias = null;
target = null;
kind = default(ImportTargetKind);
kind = default;

if (string.IsNullOrEmpty(import))
{
Expand Down Expand Up @@ -693,8 +693,8 @@ public static bool TryParseVisualBasicImportString(string import, out string ali
{
alias = null;
target = null;
kind = default(ImportTargetKind);
scope = default(VBImportScopeKind);
kind = default;
scope = default;

if (import == null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Dependencies/PooledObjects/ArrayBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void SetItem(int index, T value)
{
while (index > _builder.Count)
{
_builder.Add(default(T));
_builder.Add(default);
}

if (index == _builder.Count)
Expand Down Expand Up @@ -241,7 +241,7 @@ public ImmutableArray<T> ToImmutableOrNull()
{
if (Count == 0)
{
return default(ImmutableArray<T>);
return default;
}

return this.ToImmutable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace Microsoft.CodeAnalysis.Editor
{
internal interface IBraceMatcher
{
Task<BraceMatchingResult?> FindBracesAsync(Document document, int position, CancellationToken cancellationToken = default(CancellationToken));
Task<BraceMatchingResult?> FindBracesAsync(Document document, int position, CancellationToken cancellationToken = default);
}
}
2 changes: 1 addition & 1 deletion src/EditorFeatures/Core/IBraceMatchingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.CodeAnalysis.Editor
{
internal interface IBraceMatchingService
{
Task<BraceMatchingResult?> GetMatchingBracesAsync(Document document, int position, CancellationToken cancellationToken = default(CancellationToken));
Task<BraceMatchingResult?> GetMatchingBracesAsync(Document document, int position, CancellationToken cancellationToken = default);
}

internal struct BraceMatchingResult
Expand Down
8 changes: 4 additions & 4 deletions src/EditorFeatures/Core/IForegroundNotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ namespace Microsoft.CodeAnalysis.Editor
/// </summary>
internal interface IForegroundNotificationService
{
void RegisterNotification(Action action, IAsyncToken asyncToken, CancellationToken cancellationToken = default(CancellationToken));
void RegisterNotification(Action action, IAsyncToken asyncToken, CancellationToken cancellationToken = default);

void RegisterNotification(Action action, int delayInMS, IAsyncToken asyncToken, CancellationToken cancellationToken = default(CancellationToken));
void RegisterNotification(Action action, int delayInMS, IAsyncToken asyncToken, CancellationToken cancellationToken = default);

/// <summary>
/// if action return true, the service will call it back again when it has time.
/// </summary>
void RegisterNotification(Func<bool> action, IAsyncToken asyncToken, CancellationToken cancellationToken = default(CancellationToken));
void RegisterNotification(Func<bool> action, IAsyncToken asyncToken, CancellationToken cancellationToken = default);

void RegisterNotification(Func<bool> action, int delayInMS, IAsyncToken asyncToken, CancellationToken cancellationToken = default(CancellationToken));
void RegisterNotification(Func<bool> action, int delayInMS, IAsyncToken asyncToken, CancellationToken cancellationToken = default);
}
}
2 changes: 1 addition & 1 deletion src/EditorFeatures/Core/IInlineRenameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal interface IInlineRenameService
/// <param name="triggerSpan">The triggerSpan itself.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
/// <returns>The rename session.</returns>
InlineRenameSessionInfo StartInlineSession(Document document, TextSpan triggerSpan, CancellationToken cancellationToken = default(CancellationToken));
InlineRenameSessionInfo StartInlineSession(Document document, TextSpan triggerSpan, CancellationToken cancellationToken = default);

/// <summary>
/// Returns the currently active inline session, or null if none is active.
Expand Down
2 changes: 1 addition & 1 deletion src/EditorFeatures/Core/ILineSeparatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace Microsoft.CodeAnalysis.Editor
{
internal interface ILineSeparatorService : ILanguageService
{
Task<IEnumerable<TextSpan>> GetLineSeparatorsAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken = default(CancellationToken));
Task<IEnumerable<TextSpan>> GetLineSeparatorsAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken = default);
}
}
2 changes: 1 addition & 1 deletion src/EditorFeatures/Core/IMetadataAsSourceFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal interface IMetadataAsSourceFileService
/// from.</param>
/// <param name="symbol">The symbol whose interface to generate source for</param>
/// <param name="cancellationToken">To cancel project and document operations</param>
Task<MetadataAsSourceFile> GetGeneratedFileAsync(Project project, ISymbol symbol, CancellationToken cancellationToken = default(CancellationToken));
Task<MetadataAsSourceFile> GetGeneratedFileAsync(Project project, ISymbol symbol, CancellationToken cancellationToken = default);

bool TryAddDocumentToWorkspace(string filePath, ITextBuffer buffer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private bool TryMapToSingleSnapshotSpan(IMappingSpan mappingSpan, ITextSnapshot
var spans = mappingSpan.GetSpans(viewSnapshot);
if (spans.Count != 1)
{
span = default(SnapshotSpan);
span = default;
return false; // span is unmapped or disjoint.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static SyntaxToken FindToken(this ITextSnapshot snapshot, int position, C
var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document == null)
{
return default(SyntaxToken);
return default;
}

var root = document.GetSyntaxRootSynchronously(cancellationToken);
Expand All @@ -53,7 +53,7 @@ public static SyntaxToken FindToken(this ITextSnapshot snapshot, int position, C
/// <summary>
/// insert text to workspace and get updated version of the document
/// </summary>
public static Document InsertText(this Document document, int position, string text, CancellationToken cancellationToken = default(CancellationToken))
public static Document InsertText(this Document document, int position, string text, CancellationToken cancellationToken = default)
{
return document.ReplaceText(new TextSpan(position, 0), text, cancellationToken);
}
Expand Down Expand Up @@ -94,7 +94,7 @@ public static Document ApplyTextChanges(this Document document, IEnumerable<Text
/// <summary>
/// Update the solution so that the document with the Id has the text changes
/// </summary>
public static Solution UpdateDocument(this Solution solution, DocumentId id, IEnumerable<TextChange> textChanges, CancellationToken cancellationToken = default(CancellationToken))
public static Solution UpdateDocument(this Solution solution, DocumentId id, IEnumerable<TextChange> textChanges, CancellationToken cancellationToken = default)
{
var oldDocument = solution.GetDocument(id);
var newText = oldDocument.GetTextAsync(cancellationToken).WaitAndGetResult(cancellationToken).WithChanges(textChanges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where tok.Span.Length > 0
}
}

match = default(SyntaxToken);
match = default;
return false;
}

Expand Down
Loading

0 comments on commit 878ffad

Please sign in to comment.