From 19ffed44c79437148e8eac63f7f6c52087f31e3f Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 8 Mar 2025 09:38:54 +0000 Subject: [PATCH] Removed single loop foreach in favor of key lookup inside `GetDialogueFromProfile` --- .../Helpers/DialogueHelper.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Helpers/DialogueHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/DialogueHelper.cs index fe201c08..cdcc18d3 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/DialogueHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/DialogueHelper.cs @@ -109,21 +109,21 @@ public class DialogueHelper( return profile.DialogueRecords ?? (profile.DialogueRecords = new Dictionary()); } + /// + /// Find and return a profiles dialogue by id + /// + /// Profile to look in + /// Dialog to return + /// Dialogue public Models.Eft.Profile.Dialogue? GetDialogueFromProfile(string profileId, string dialogueId) { - Models.Eft.Profile.Dialogue? returnDialogue = null; var dialogues = GetDialogsForProfile(profileId); - - foreach (var dialogue in dialogues.Values) + if (dialogues.TryGetValue(dialogueId, out var dialogue)) { - if (dialogue.Id == dialogueId) - { - returnDialogue = dialogue; - } - - break; + return dialogue; } - return returnDialogue; + _logger.Error($"Unable to find a dialogue with id: {dialogueId} in profile: {profileId}"); + return null; } }