mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 10:52:56 +00:00
various cleanups and micro-optimizations
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
b3722d96b0
commit
6f754bfc90
6 changed files with 38 additions and 70 deletions
|
@ -78,7 +78,7 @@ void debugBinaryString(const QByteArray &input)
|
|||
printf("\n\n");
|
||||
}
|
||||
|
||||
void debugBinaryString(const char *data, qint64 maxlen)
|
||||
inline void debugBinaryString(const char *data, qint64 maxlen)
|
||||
{
|
||||
debugBinaryString(QByteArray(data, maxlen));
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public:
|
|||
bool isEmpty() const {
|
||||
return len == 0;
|
||||
}
|
||||
void skip(int n) {
|
||||
void skip(const int n) {
|
||||
if (n >= len) {
|
||||
clear();
|
||||
} else {
|
||||
|
@ -97,30 +97,30 @@ public:
|
|||
int getChar() {
|
||||
if (len == 0)
|
||||
return -1;
|
||||
int ch = uchar(*first);
|
||||
const int ch = uchar(*first);
|
||||
len--;
|
||||
first++;
|
||||
return ch;
|
||||
}
|
||||
int read(char* target, int size) {
|
||||
int r = qMin(size, len);
|
||||
int read(char* target, const int size) {
|
||||
const int r = qMin(size, len);
|
||||
memcpy(target, first, r);
|
||||
len -= r;
|
||||
first += r;
|
||||
return r;
|
||||
}
|
||||
int peek(char* target, int size) {
|
||||
int r = qMin(size, len);
|
||||
int peek(char* target, const int size) {
|
||||
const int r = qMin(size, len);
|
||||
memcpy(target, first, r);
|
||||
return r;
|
||||
}
|
||||
char* reserve(int size) {
|
||||
char* reserve(const int size) {
|
||||
makeSpace(size + len, freeSpaceAtEnd);
|
||||
char* writePtr = first + len;
|
||||
len += size;
|
||||
return writePtr;
|
||||
}
|
||||
void chop(int size) {
|
||||
void chop(const int size) {
|
||||
if (size >= len) {
|
||||
clear();
|
||||
} else {
|
||||
|
@ -129,7 +129,7 @@ public:
|
|||
}
|
||||
QByteArray readAll() {
|
||||
char* f = first;
|
||||
int l = len;
|
||||
const int l = len;
|
||||
clear();
|
||||
return QByteArray(f, l);
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ private:
|
|||
size_t newCapacity = qMax(capacity, size_t(QIODEVICE_BUFFERSIZE));
|
||||
while (newCapacity < required)
|
||||
newCapacity *= 2;
|
||||
int moveOffset = (where == freeSpaceAtEnd) ? 0 : newCapacity - len;
|
||||
const int moveOffset = (where == freeSpaceAtEnd) ? 0 : newCapacity - len;
|
||||
if (newCapacity > capacity) {
|
||||
// allocate more space
|
||||
char* newBuf = new char[newCapacity];
|
||||
|
@ -186,7 +186,6 @@ private:
|
|||
first = buf + moveOffset;
|
||||
}
|
||||
|
||||
private:
|
||||
// length of the unread data
|
||||
int len;
|
||||
// start of the unread data
|
||||
|
@ -197,7 +196,7 @@ private:
|
|||
size_t capacity;
|
||||
};
|
||||
|
||||
class Q_CORE_EXPORT QIODevicePrivate
|
||||
class QIODevicePrivate
|
||||
#ifndef QT_NO_QOBJECT
|
||||
: public QObjectPrivate
|
||||
#endif
|
||||
|
|
|
@ -154,37 +154,10 @@ QBitArray::QBitArray(int size, bool value)
|
|||
int QBitArray::count(bool on) const
|
||||
{
|
||||
int numBits = 0;
|
||||
int len = size();
|
||||
#if 0
|
||||
const int len = size();
|
||||
for (int i = 0; i < len; ++i)
|
||||
numBits += testBit(i);
|
||||
#else
|
||||
// See http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
|
||||
const quint8 *bits = reinterpret_cast<const quint8 *>(d.data()) + 1;
|
||||
while (len >= 32) {
|
||||
quint32 v = quint32(bits[0]) | (quint32(bits[1]) << 8) | (quint32(bits[2]) << 16) | (quint32(bits[3]) << 24);
|
||||
quint32 c = ((v & 0xfff) * Q_UINT64_C(0x1001001001001) & Q_UINT64_C(0x84210842108421)) % 0x1f;
|
||||
c += (((v & 0xfff000) >> 12) * Q_UINT64_C(0x1001001001001) & Q_UINT64_C(0x84210842108421)) % 0x1f;
|
||||
c += ((v >> 24) * Q_UINT64_C(0x1001001001001) & Q_UINT64_C(0x84210842108421)) % 0x1f;
|
||||
len -= 32;
|
||||
bits += 4;
|
||||
numBits += int(c);
|
||||
}
|
||||
while (len >= 24) {
|
||||
quint32 v = quint32(bits[0]) | (quint32(bits[1]) << 8) | (quint32(bits[2]) << 16);
|
||||
quint32 c = ((v & 0xfff) * Q_UINT64_C(0x1001001001001) & Q_UINT64_C(0x84210842108421)) % 0x1f;
|
||||
c += (((v & 0xfff000) >> 12) * Q_UINT64_C(0x1001001001001) & Q_UINT64_C(0x84210842108421)) % 0x1f;
|
||||
len -= 24;
|
||||
bits += 3;
|
||||
numBits += int(c);
|
||||
}
|
||||
while (len >= 0) {
|
||||
if (bits[len / 8] & (1 << ((len - 1) & 7)))
|
||||
++numBits;
|
||||
--len;
|
||||
}
|
||||
#endif
|
||||
return on ? numBits : size() - numBits;
|
||||
return on ? numBits : len - numBits;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -694,8 +667,8 @@ QDataStream &operator>>(QDataStream &in, QBitArray &ba)
|
|||
quint32 len;
|
||||
in >> len;
|
||||
if (len == 0) {
|
||||
ba.clear();
|
||||
return in;
|
||||
ba.clear();
|
||||
return in;
|
||||
}
|
||||
|
||||
const quint32 Step = 8 * 1024 * 1024;
|
||||
|
|
|
@ -2183,7 +2183,7 @@ QList<QByteArray> QByteArray::split(char sep) const
|
|||
ba.repeated(4); // returns "abababab"
|
||||
\endcode
|
||||
*/
|
||||
QByteArray QByteArray::repeated(int times) const
|
||||
QByteArray QByteArray::repeated(const int times) const
|
||||
{
|
||||
if (d->size == 0)
|
||||
return *this;
|
||||
|
@ -2229,7 +2229,7 @@ QByteArray QByteArray::repeated(int times) const
|
|||
\sa lastIndexOf(), contains(), count()
|
||||
*/
|
||||
|
||||
int QByteArray::indexOf(const QByteArray &ba, int from) const
|
||||
int QByteArray::indexOf(const QByteArray &ba, const int from) const
|
||||
{
|
||||
const int ol = ba.d->size;
|
||||
if (ol == 0)
|
||||
|
@ -2271,7 +2271,7 @@ int QByteArray::indexOf(const QByteArray &ba, int from) const
|
|||
\a str in the byte array, searching forward from index position \a
|
||||
from. Returns -1 if \a str could not be found.
|
||||
*/
|
||||
int QByteArray::indexOf(const char *c, int from) const
|
||||
int QByteArray::indexOf(const char *c, const int from) const
|
||||
{
|
||||
const int ol = qstrlen(c);
|
||||
if (ol == 1)
|
||||
|
@ -2575,7 +2575,7 @@ bool QByteArray::endsWith(const char *str) const
|
|||
{
|
||||
if (!str || !*str)
|
||||
return true;
|
||||
int len = qstrlen(str);
|
||||
const int len = qstrlen(str);
|
||||
if (d->size < len)
|
||||
return false;
|
||||
return qstrncmp(d->data + d->size - len, str, len) == 0;
|
||||
|
@ -2681,11 +2681,9 @@ QByteArray QByteArray::toLower() const
|
|||
{
|
||||
QByteArray s(*this);
|
||||
uchar *p = reinterpret_cast<uchar *>(s.data());
|
||||
if (p) {
|
||||
while (*p) {
|
||||
*p = QChar::toLower((ushort)*p);
|
||||
p++;
|
||||
}
|
||||
while (*p) {
|
||||
*p = QChar::toLower((ushort)*p);
|
||||
p++;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
@ -2704,11 +2702,9 @@ QByteArray QByteArray::toUpper() const
|
|||
{
|
||||
QByteArray s(*this);
|
||||
uchar *p = reinterpret_cast<uchar *>(s.data());
|
||||
if (p) {
|
||||
while (*p) {
|
||||
*p = QChar::toUpper((ushort)*p);
|
||||
p++;
|
||||
}
|
||||
while (*p) {
|
||||
*p = QChar::toUpper((ushort)*p);
|
||||
p++;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -164,11 +164,11 @@ public:
|
|||
QByteRef operator[](uint i);
|
||||
|
||||
int indexOf(char c, int from = 0) const;
|
||||
int indexOf(const char *c, int from = 0) const;
|
||||
int indexOf(const QByteArray &a, int from = 0) const;
|
||||
int lastIndexOf(char c, int from = -1) const;
|
||||
int lastIndexOf(const char *c, int from = -1) const;
|
||||
int lastIndexOf(const QByteArray &a, int from = -1) const;
|
||||
int indexOf(const char *c, const int from = 0) const;
|
||||
int indexOf(const QByteArray &a, const int from = 0) const;
|
||||
int lastIndexOf(char c, const int from = -1) const;
|
||||
int lastIndexOf(const char *c, const int from = -1) const;
|
||||
int lastIndexOf(const QByteArray &a, const int from = -1) const;
|
||||
|
||||
bool contains(char c) const;
|
||||
bool contains(const char *a) const;
|
||||
|
@ -231,18 +231,18 @@ public:
|
|||
|
||||
QList<QByteArray> split(char sep) const;
|
||||
|
||||
QByteArray repeated(int times) const;
|
||||
QByteArray repeated(const int times) const;
|
||||
|
||||
#ifndef QT_NO_CAST_TO_ASCII
|
||||
QT_ASCII_CAST_WARN QByteArray &append(const QString &s);
|
||||
QT_ASCII_CAST_WARN QByteArray &insert(int i, const QString &s);
|
||||
QT_ASCII_CAST_WARN QByteArray &insert(const int i, const QString &s);
|
||||
QT_ASCII_CAST_WARN QByteArray &replace(const QString &before, const char *after);
|
||||
QT_ASCII_CAST_WARN QByteArray &replace(char c, const QString &after);
|
||||
QT_ASCII_CAST_WARN QByteArray &replace(const QString &before, const QByteArray &after);
|
||||
|
||||
QT_ASCII_CAST_WARN QByteArray &operator+=(const QString &s);
|
||||
QT_ASCII_CAST_WARN int indexOf(const QString &s, int from = 0) const;
|
||||
QT_ASCII_CAST_WARN int lastIndexOf(const QString &s, int from = -1) const;
|
||||
QT_ASCII_CAST_WARN int indexOf(const QString &s, const int from = 0) const;
|
||||
QT_ASCII_CAST_WARN int lastIndexOf(const QString &s, int const from = -1) const;
|
||||
#endif
|
||||
#ifndef QT_NO_CAST_FROM_ASCII
|
||||
inline QT_ASCII_CAST_WARN bool operator==(const QString &s2) const;
|
||||
|
|
|
@ -51,7 +51,6 @@ QT_BEGIN_NAMESPACE
|
|||
class QCryptographicHashPrivate
|
||||
{
|
||||
public:
|
||||
QCryptographicHash::Algorithm method;
|
||||
MD4_CTX md4Context;
|
||||
MD5_CTX md5Context;
|
||||
SHA_CTX sha1Context;
|
||||
|
@ -59,6 +58,7 @@ public:
|
|||
SHA256_CTX sha256Context;
|
||||
SHA512_CTX sha384Context;
|
||||
SHA512_CTX sha512Context;
|
||||
QCryptographicHash::Algorithm method;
|
||||
QByteArray result;
|
||||
};
|
||||
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
/*!
|
||||
Constructs an object that can be used to create a cryptographic hash from data using \a method.
|
||||
*/
|
||||
QCryptographicHash::QCryptographicHash(Algorithm method)
|
||||
QCryptographicHash::QCryptographicHash(QCryptographicHash::Algorithm method)
|
||||
: d(new QCryptographicHashPrivate)
|
||||
{
|
||||
d->method = method;
|
||||
|
@ -268,7 +268,7 @@ QByteArray QCryptographicHash::result() const
|
|||
/*!
|
||||
Returns the hash of \a data using \a method.
|
||||
*/
|
||||
QByteArray QCryptographicHash::hash(const QByteArray &data, Algorithm method)
|
||||
QByteArray QCryptographicHash::hash(const QByteArray &data, QCryptographicHash::Algorithm method)
|
||||
{
|
||||
QCryptographicHash hash(method);
|
||||
hash.addData(data);
|
||||
|
|
Loading…
Add table
Reference in a new issue