зеркало из https://github.com/mozilla/gecko-dev.git
Bug 935789, part 2: Implement RotateLeft/RotateRight in MFBT and use them, r=Waldo.
--HG-- extra : rebase_source : efda8cfde4ec1b8cee007f528d682830f43f9111
This commit is contained in:
Родитель
f6366dd338
Коммит
f8f4ab7e4c
|
@ -8,11 +8,11 @@
|
|||
|
||||
#include "gfxPlatform.h"
|
||||
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "nsAutoRef.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsTHashtable.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "prbit.h" // for PR_ROTATE_LEFT32
|
||||
|
||||
#include <fontconfig/fontconfig.h>
|
||||
|
||||
|
@ -165,7 +165,7 @@ protected:
|
|||
static PLDHashNumber HashKey(const FcChar8 *aKey) {
|
||||
uint32_t hash = 0;
|
||||
for (const FcChar8 *c = aKey; *c != '\0'; ++c) {
|
||||
hash = PR_ROTATE_LEFT32(hash, 3) ^ FcToLower(*c);
|
||||
hash = mozilla::RotateLeft(hash, 3) ^ FcToLower(*c);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
|
|
@ -451,6 +451,30 @@ RoundUpPow2(size_t x)
|
|||
return size_t(1) << CeilingLog2(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates the bits of the given value left by the amount of the shift width.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T
|
||||
RotateLeft(const T t, uint_fast8_t shift)
|
||||
{
|
||||
MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!");
|
||||
static_assert(IsUnsigned<T>::value, "Rotates require unsigned values");
|
||||
return (t << shift) | (t >> (sizeof(T) * CHAR_BIT - shift));
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates the bits of the given value right by the amount of the shift width.
|
||||
*/
|
||||
template<typename T>
|
||||
inline T
|
||||
RotateRight(const T t, uint_fast8_t shift)
|
||||
{
|
||||
MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!");
|
||||
static_assert(IsUnsigned<T>::value, "Rotates require unsigned values");
|
||||
return (t >> shift) | (t << (sizeof(T) * CHAR_BIT - shift));
|
||||
}
|
||||
|
||||
} /* namespace mozilla */
|
||||
|
||||
#endif /* mozilla_MathAlgorithms_h */
|
||||
|
|
|
@ -42,13 +42,13 @@
|
|||
#include "nsNetUtil.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
|
||||
#include "plbase64.h"
|
||||
#include "prmem.h"
|
||||
#include "prnetdb.h"
|
||||
#include "prbit.h"
|
||||
#include "zlib.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -1515,7 +1515,7 @@ WebSocketChannel::ApplyMask(uint32_t mask, uint8_t *data, uint64_t len)
|
|||
|
||||
while (len && (reinterpret_cast<uintptr_t>(data) & 3)) {
|
||||
*data ^= mask >> 24;
|
||||
mask = PR_ROTATE_LEFT32(mask, 8);
|
||||
mask = RotateLeft(mask, 8);
|
||||
data++;
|
||||
len--;
|
||||
}
|
||||
|
@ -1536,7 +1536,7 @@ WebSocketChannel::ApplyMask(uint32_t mask, uint8_t *data, uint64_t len)
|
|||
|
||||
while (len) {
|
||||
*data ^= mask >> 24;
|
||||
mask = PR_ROTATE_LEFT32(mask, 8);
|
||||
mask = RotateLeft(mask, 8);
|
||||
data++;
|
||||
len--;
|
||||
}
|
||||
|
@ -1779,7 +1779,7 @@ WebSocketChannel::PrimeNewOutgoingMessage()
|
|||
|
||||
while (payload < (mOutHeader + mHdrOutToSend)) {
|
||||
*payload ^= mask >> 24;
|
||||
mask = PR_ROTATE_LEFT32(mask, 8);
|
||||
mask = RotateLeft(mask, 8);
|
||||
payload++;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче