Browse Source

Replaced Math.Pow with left shift operator

pull/743/head
Chris Johnston 8 years ago
parent
commit
00df8fb784
3 changed files with 7 additions and 8 deletions
  1. +1
    -1
      src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs
  2. +2
    -3
      src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs
  3. +4
    -4
      src/Discord.Net.Core/Entities/Permissions/OverwritePermissions.cs

+ 1
- 1
src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs View File

@@ -143,7 +143,7 @@ namespace Discord
var perms = new List<ChannelPermission>(); var perms = new List<ChannelPermission>();
for (byte i = 0; i < Permissions.MaxBits; i++) for (byte i = 0; i < Permissions.MaxBits; i++)
{ {
ulong flag = (ulong)Math.Pow(2, i);
ulong flag = ((ulong)1 << i);
if ((RawValue & flag) != 0) if ((RawValue & flag) != 0)
perms.Add((ChannelPermission)flag); perms.Add((ChannelPermission)flag);
} }


+ 2
- 3
src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;


namespace Discord namespace Discord
@@ -161,7 +160,7 @@ namespace Discord
// each of the GuildPermissions increments by 2^i from 0 to MaxBits // each of the GuildPermissions increments by 2^i from 0 to MaxBits
for (byte i = 0; i < Permissions.MaxBits; i++) for (byte i = 0; i < Permissions.MaxBits; i++)
{ {
ulong flag = (ulong)Math.Pow(2, i);
ulong flag = ((ulong)1 << i);
if ((RawValue & flag) != 0) if ((RawValue & flag) != 0)
perms.Add((GuildPermission)flag); perms.Add((GuildPermission)flag);
} }


+ 4
- 4
src/Discord.Net.Core/Entities/Permissions/OverwritePermissions.cs View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;


namespace Discord namespace Discord
@@ -131,7 +130,8 @@ namespace Discord
var perms = new List<ChannelPermission>(); var perms = new List<ChannelPermission>();
for (byte i = 0; i < Permissions.MaxBits; i++) for (byte i = 0; i < Permissions.MaxBits; i++)
{ {
ulong flag = (ulong)Math.Pow(2, i);
// first operand must be long or ulong to shift >31 bits
ulong flag = ((ulong)1 << i);
if ((AllowValue & flag) != 0) if ((AllowValue & flag) != 0)
perms.Add((ChannelPermission)flag); perms.Add((ChannelPermission)flag);
} }
@@ -142,7 +142,7 @@ namespace Discord
var perms = new List<ChannelPermission>(); var perms = new List<ChannelPermission>();
for (byte i = 0; i < Permissions.MaxBits; i++) for (byte i = 0; i < Permissions.MaxBits; i++)
{ {
ulong flag = (ulong)Math.Pow(2, i);
ulong flag = ((ulong)1 << i);
if ((DenyValue & flag) != 0) if ((DenyValue & flag) != 0)
perms.Add((ChannelPermission)flag); perms.Add((ChannelPermission)flag);
} }


Loading…
Cancel
Save