Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate dictionary lookups #10003

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ private async Task<List<SupportRequestViewModel>> GetSupportRequestsAsync(int pa
viewModel.IssueStatusName = issue.IssueStatus.Name;

// Email may not be available, because the delete workflow hard deletes unconfirmed users.
if (issue.UserKey.HasValue && userEmails.ContainsKey(issue.UserKey.Value))
if (issue.UserKey.HasValue && userEmails.TryGetValue(issue.UserKey.Value, out var email))
{
viewModel.UserEmail = userEmails[issue.UserKey.Value];
viewModel.UserEmail = email;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/NuGetGallery/Extensions/RouteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public static void MapRoute(
public static string ObfuscateUrlPath(this Route route, string urlPath)
{
var path = route.Url;
if (!ObfuscatedRouteMap.ContainsKey(path))
if (!ObfuscatedRouteMap.TryGetValue(path, out var metadatas))
{
return null;
}
var metadatas = ObfuscatedRouteMap[path];

string[] segments = urlPath.Split('/');
foreach (var metadata in metadatas)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public override string SelectAction(ODataPath odataPath, HttpControllerContext c
if (action != null)
{
var routeValues = controllerContext.RouteData.Values;
if (routeValues.ContainsKey(ODataRouteConstants.Key))
if (routeValues.TryGetValue(ODataRouteConstants.Key, out var value))
{
var keyRaw = routeValues[ODataRouteConstants.Key] as string;
var keyRaw = value as string;
if (keyRaw != null)
{
if (!CompositeODataKeyHelper.TryEnrichRouteValues(keyRaw, routeValues))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public TestGalleryConfigurationService()

protected override string GetAppSetting(string settingName)
{
if (Settings.ContainsKey(settingName))
if (Settings.TryGetValue(settingName, out var setting))
{
return Settings[settingName];
return setting;
}

// Will cause ResolveConfigObject to populate a class with default values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ public IDependencyScope BeginScope()

public object GetService(Type serviceType)
{
if (_registeredServices.ContainsKey(serviceType))
if (_registeredServices.TryGetValue(serviceType, out var service))
{
return _registeredServices[serviceType];
return service;
}
return (object)null;
}

public IEnumerable<object> GetServices(Type serviceType)
{
if (_registeredServices.ContainsKey(serviceType))
if (_registeredServices.TryGetValue(serviceType, out var service))
{
return new[] { _registeredServices[serviceType] };
return new[] {service};
}
return Enumerable.Empty<object>();
}
Expand Down