Skip to content

Commit

Permalink
Add some NotNullWhen attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Oct 6, 2023
1 parent 904186b commit 870c667
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 7 additions & 6 deletions TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -814,7 +815,7 @@ private void DrawFragmentPart(List<(SKImageInfo info, SKBitmap bitmap)> sectionI
DrawRegularMessage(sectionImages, emotePositionList, ref drawPos, defaultPos, bitsCount, fragmentPart, highlightWords);
}

static bool TryGetTwitchEmote(List<TwitchEmote> twitchEmoteList, ReadOnlySpan<char> emoteName, out TwitchEmote twitchEmote)
static bool TryGetTwitchEmote(List<TwitchEmote> twitchEmoteList, ReadOnlySpan<char> emoteName, [NotNullWhen(true)] out TwitchEmote twitchEmote)
{
// Enumerating over a span is faster than a list
var emoteListSpan = CollectionsMarshal.AsSpan(twitchEmoteList);
Expand All @@ -827,7 +828,7 @@ static bool TryGetTwitchEmote(List<TwitchEmote> twitchEmoteList, ReadOnlySpan<ch
}
}

twitchEmote = default;
twitchEmote = null;
return false;
}
}
Expand Down Expand Up @@ -1076,7 +1077,7 @@ private void DrawRegularMessage(List<(SKImageInfo info, SKBitmap bitmap)> sectio
DrawText(fragmentString, messageFont, true, sectionImages, ref drawPos, defaultPos, highlightWords);
}

static bool TryGetCheerEmote(List<CheerEmote> cheerEmoteList, ReadOnlySpan<char> prefix, out CheerEmote cheerEmote)
static bool TryGetCheerEmote(List<CheerEmote> cheerEmoteList, ReadOnlySpan<char> prefix, [NotNullWhen(true)] out CheerEmote cheerEmote)
{
// Enumerating over a span is faster than a list
var cheerEmoteListSpan = CollectionsMarshal.AsSpan(cheerEmoteList);
Expand All @@ -1089,7 +1090,7 @@ static bool TryGetCheerEmote(List<CheerEmote> cheerEmoteList, ReadOnlySpan<char>
}
}

cheerEmote = default;
cheerEmote = null;
return false;
}
}
Expand Down Expand Up @@ -1125,7 +1126,7 @@ private void DrawFirstPartyEmote(List<(SKImageInfo info, SKBitmap bitmap)> secti
DrawText(fragment.text, messageFont, true, sectionImages, ref drawPos, defaultPos, highlightWords);
}

static bool TryGetTwitchEmote(List<TwitchEmote> twitchEmoteList, ReadOnlySpan<char> emoteId, out TwitchEmote twitchEmote)
static bool TryGetTwitchEmote(List<TwitchEmote> twitchEmoteList, ReadOnlySpan<char> emoteId, [NotNullWhen(true)] out TwitchEmote twitchEmote)
{
// Enumerating over a span is faster than a list
var emoteListSpan = CollectionsMarshal.AsSpan(twitchEmoteList);
Expand All @@ -1138,7 +1139,7 @@ static bool TryGetTwitchEmote(List<TwitchEmote> twitchEmoteList, ReadOnlySpan<ch
}
}

twitchEmote = default;
twitchEmote = null;
return false;
}
}
Expand Down
4 changes: 3 additions & 1 deletion TwitchDownloaderWPF/Services/ThumbnailService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Media.Imaging;

namespace TwitchDownloaderWPF.Services
Expand All @@ -7,6 +8,7 @@ public static class ThumbnailService
{
public const string THUMBNAIL_MISSING_URL = @"https://vod-secure.twitch.tv/_404/404_processing_320x180.png";

/// <exception cref="ArgumentNullException">The <paramref name="thumbUrl"/> was <see langword="null"/></exception>
public static BitmapImage GetThumb(string thumbUrl, BitmapCacheOption cacheOption = BitmapCacheOption.OnLoad)
{
ArgumentNullException.ThrowIfNull(thumbUrl);
Expand All @@ -25,7 +27,7 @@ public static BitmapImage GetThumb(string thumbUrl, BitmapCacheOption cacheOptio
return img;
}

public static bool TryGetThumb(string thumbUrl, out BitmapImage thumbnail)
public static bool TryGetThumb(string thumbUrl, [NotNullWhen(true)] out BitmapImage thumbnail)
{
if (string.IsNullOrWhiteSpace(thumbUrl))
{
Expand Down

0 comments on commit 870c667

Please sign in to comment.