Optimize Guid comparisons

* Use Guid.Equals(Guid) instead of the == override
* Ban the usage of Guid.Equals(Object) to prevent accidental boxing
* Compare to default(Guid) instead of Guid.Empty
This commit is contained in:
Bond_009
2022-02-21 14:15:09 +01:00
parent bbac59c6d6
commit f50a250cd9
66 changed files with 355 additions and 326 deletions

View File

@@ -107,7 +107,7 @@ namespace Jellyfin.Server.Implementations.Users
/// <inheritdoc/>
public User? GetUserById(Guid id)
{
if (id == Guid.Empty)
if (id.Equals(default))
{
throw new ArgumentException("Guid can't be empty", nameof(id));
}
@@ -146,8 +146,7 @@ namespace Jellyfin.Server.Implementations.Users
if (await dbContext.Users
.AsQueryable()
.Where(u => u.Username == newName && u.Id != user.Id)
.AnyAsync()
.AnyAsync(u => u.Username == newName && !u.Id.Equals(user.Id))
.ConfigureAwait(false))
{
throw new ArgumentException(string.Format(
@@ -597,7 +596,7 @@ namespace Jellyfin.Server.Implementations.Users
.Include(u => u.Preferences)
.Include(u => u.AccessSchedules)
.Include(u => u.ProfileImage)
.FirstOrDefault(u => u.Id == userId)
.FirstOrDefault(u => u.Id.Equals(userId))
?? throw new ArgumentException("No user exists with given Id!");
user.SubtitleMode = config.SubtitleMode;
@@ -631,7 +630,7 @@ namespace Jellyfin.Server.Implementations.Users
.Include(u => u.Preferences)
.Include(u => u.AccessSchedules)
.Include(u => u.ProfileImage)
.FirstOrDefault(u => u.Id == userId)
.FirstOrDefault(u => u.Id.Equals(userId))
?? throw new ArgumentException("No user exists with given Id!");
// The default number of login attempts is 3, but for some god forsaken reason it's sent to the server as "0"