Skip to content

Commit

Permalink
Avoid chaining Where and First/FirstOrDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoco007 committed Dec 20, 2023
1 parent 1d2f526 commit f888888
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/Components/ButtonArtworkImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void SetArtwork(string path)
{
if (image == null)
{
image = GetComponentsInChildren<Image>().Where(x => x.name == "BGArtwork").FirstOrDefault();
image = GetComponentsInChildren<Image>().FirstOrDefault(x => x.name == "BGArtwork");
}

if (image == null)
Expand Down
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/FontManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private static bool TryGetFontInfoByFamily(string family, out FontInfo info, str
{
if (fontInfoLookup.TryGetValue(family, out List<FontInfo> fonts))
{
info = fonts.Where(p => p?.Info.Subfamily == subfamily).FirstOrDefault();
info = fonts.FirstOrDefault(p => p?.Info.Subfamily == subfamily);
if (info == null)
{
if (!fallbackIfNoSubfamily)
Expand Down
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/GameplaySetup/GameplaySetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void SetTabVisibility(string name, bool isVisible)
return;
}

GameplaySetupMenu menu = _menus.OfType<GameplaySetupMenu>().Where(x => x.name == name).FirstOrDefault();
GameplaySetupMenu menu = _menus.OfType<GameplaySetupMenu>().FirstOrDefault(x => x.name == name);
menu?.SetVisible(isVisible);
}

Expand Down
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/OpenType/OpenTypeFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public OpenTypeFont(OffsetTable offsets, OpenTypeFontReader reader, bool lazyLoa
offsetTable = offsets;
tables = reader.ReadTableRecords(offsetTable);
nameTableRecord = tables.Select(t => new TableRecord?(t))
.Where(t => t.Value.TableTag == OpenTypeTag.NAME).FirstOrDefault();
.FirstOrDefault(t => t.Value.TableTag == OpenTypeTag.NAME);

if (lazyLoad)
{
Expand Down
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/Tags/LoadingIndicatorTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override GameObject CreateObject(Transform parent)
{
if (loadingTemplate == null)
{
loadingTemplate = Resources.FindObjectsOfTypeAll<ImageView>().Where(x => x.gameObject.name == "LoadingIndicator").First().gameObject;
loadingTemplate = Resources.FindObjectsOfTypeAll<ImageView>().First(x => x.gameObject.name == "LoadingIndicator").gameObject;
}

GameObject loadingIndicator = Object.Instantiate(loadingTemplate, parent, false);
Expand Down
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/Tags/ModalColorPickerTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override GameObject CreateObject(Transform parent)

if (currentColorTemplate == null)
{
currentColorTemplate = Resources.FindObjectsOfTypeAll<ImageView>().Where(iv => iv.transform.parent != null).First(iv => iv.gameObject.name == "SaberColorA" && iv.transform.parent.name == "ColorSchemeView");
currentColorTemplate = Resources.FindObjectsOfTypeAll<ImageView>().First(iv => iv.transform.parent != null && iv.gameObject.name == "SaberColorA" && iv.transform.parent.name == "ColorSchemeView");
}

RGBPanelController rgbController = Object.Instantiate(rgbTemplate, gameObject.transform, false);
Expand Down
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/Tags/PageButtonTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override GameObject CreateObject(Transform parent)
(button.transform as RectTransform).pivot = new Vector2(.5f, .5f);

ButtonIconImage btnIcon = button.gameObject.AddComponent<ButtonIconImage>();
btnIcon.image = button.gameObject.GetComponentsInChildren<Image>(true).Where(x => x.gameObject.name == "Icon").FirstOrDefault();
btnIcon.image = button.gameObject.GetComponentsInChildren<Image>(true).FirstOrDefault(x => x.gameObject.name == "Icon");

button.gameObject.SetActive(true);
return button.gameObject;
Expand Down
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/Tags/Settings/ColorSettingTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override GameObject CreateObject(Transform parent)

if (colorImage == null)
{
colorImage = Resources.FindObjectsOfTypeAll<Image>().Where(i => i.sprite != null).First(i => i.gameObject.name == "ColorImage" && i.sprite.name == "NoteCircle");
colorImage = Resources.FindObjectsOfTypeAll<Image>().First(i => i.sprite != null && i.gameObject.name == "ColorImage" && i.sprite.name == "NoteCircle");
}

Image instance = Object.Instantiate(colorImage, valuePick, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void Setup()
{
if (dropdownTemplate == null)
{
dropdownTemplate = Resources.FindObjectsOfTypeAll<SimpleTextDropdown>().Where(td => td.transform.parent != null).First(td => td.transform.parent.name == "NormalLevels").transform.parent.gameObject;
dropdownTemplate = Resources.FindObjectsOfTypeAll<SimpleTextDropdown>().First(td => td.transform.parent != null && td.transform.parent.name == "NormalLevels").transform.parent.gameObject;
}

safePrefab = Object.Instantiate(dropdownTemplate);
Expand Down
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/Tags/TabSelectorTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override GameObject CreateObject(Transform parent)
{
if (segmentControlTemplate == null)
{
segmentControlTemplate = Resources.FindObjectsOfTypeAll<TextSegmentedControl>().Where(x => x.transform.parent.name == "PlayerStatisticsViewController" && x._container != null).FirstOrDefault();
segmentControlTemplate = Resources.FindObjectsOfTypeAll<TextSegmentedControl>().FirstOrDefault(x => x.transform.parent.name == "PlayerStatisticsViewController" && x._container != null);
}

TextSegmentedControl textSegmentedControl = DiContainer.InstantiatePrefabForComponent<TextSegmentedControl>(segmentControlTemplate, parent);
Expand Down
4 changes: 2 additions & 2 deletions BeatSaberMarkupLanguage/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static Sprite EditIcon
{
if (editIcon == null)
{
editIcon = Resources.FindObjectsOfTypeAll<Image>().Where(x => x.sprite != null).First(x => x.sprite.name == "EditIcon").sprite;
editIcon = Resources.FindObjectsOfTypeAll<Image>().First(x => x.sprite != null && x.sprite.name == "EditIcon").sprite;
}

return editIcon;
Expand Down Expand Up @@ -541,7 +541,7 @@ public static Sprite WhitePixel
{
if (!whitePixel)
{
whitePixel = Resources.FindObjectsOfTypeAll<Image>().Where(i => i.sprite != null).First(i => i.sprite.name == "WhitePixel").sprite;
whitePixel = Resources.FindObjectsOfTypeAll<Image>().First(i => i.sprite != null && i.sprite.name == "WhitePixel").sprite;
}

return whitePixel;
Expand Down

0 comments on commit f888888

Please sign in to comment.