Replace QVector, QList with std::vector, std::list
An exception is made of TexPool, which will need a bit more testing before transitioning to std containers. Also replace 'int' with 'size_t' where it is used only as an array index.
This commit is contained in:
parent
8215bc7e7d
commit
231e38ae8e
16 changed files with 188 additions and 165 deletions
|
@ -34,7 +34,7 @@
|
|||
#include <libgen.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <QVector>
|
||||
#include <vector>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -312,7 +312,7 @@ MRB_METHOD(fileClose)
|
|||
}
|
||||
|
||||
static void
|
||||
readLine(FILE *f, QVector<char> &buffer)
|
||||
readLine(FILE *f, std::vector<char> &buffer)
|
||||
{
|
||||
buffer.clear();
|
||||
|
||||
|
@ -326,7 +326,7 @@ readLine(FILE *f, QVector<char> &buffer)
|
|||
if (c == '\n' || c == EOF)
|
||||
break;
|
||||
|
||||
buffer.append(c);
|
||||
buffer.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -340,19 +340,19 @@ MRB_METHOD(fileEachLine)
|
|||
mrb_get_args(mrb, "&", &block);
|
||||
|
||||
(void) f;
|
||||
QVector<char> buffer;
|
||||
std::vector<char> buffer;
|
||||
|
||||
mrb_value str = mrb_str_buf_new(mrb, 0);
|
||||
|
||||
while (feof(f) == 0)
|
||||
{
|
||||
GUARD_ERRNO( readLine(f, buffer); )
|
||||
if (buffer.isEmpty() && feof(f) != 0)
|
||||
if (buffer.empty() && feof(f) != 0)
|
||||
break;
|
||||
|
||||
size_t lineLen = buffer.count();
|
||||
size_t lineLen = buffer.size();
|
||||
mrb_str_resize(mrb, str, lineLen);
|
||||
memcpy(RSTRING_PTR(str), buffer.constData(), lineLen);
|
||||
memcpy(RSTRING_PTR(str), &buffer[0], lineLen);
|
||||
|
||||
mrb_yield(mrb, block, str);
|
||||
}
|
||||
|
@ -468,15 +468,15 @@ MRB_METHOD(fileReadLines)
|
|||
}
|
||||
|
||||
mrb_value ary = mrb_ary_new(mrb);
|
||||
QVector<char> buffer;
|
||||
std::vector<char> buffer;
|
||||
|
||||
while (feof(f) == 0)
|
||||
{
|
||||
GUARD_ERRNO( readLine(f, buffer); )
|
||||
if (buffer.isEmpty() && feof(f) != 0)
|
||||
if (buffer.empty() && feof(f) != 0)
|
||||
break;
|
||||
|
||||
mrb_value str = mrb_str_new(mrb, buffer.constData(), buffer.size());
|
||||
mrb_value str = mrb_str_new(mrb, &buffer[0], buffer.size());
|
||||
mrb_ary_push(mrb, ary, str);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#include "../binding-util.h"
|
||||
#include "file.h"
|
||||
|
@ -40,7 +41,6 @@
|
|||
|
||||
#include <SDL_timer.h>
|
||||
|
||||
#include <QVector>
|
||||
#include <QHash>
|
||||
#include <QByteArray>
|
||||
|
||||
|
@ -110,19 +110,27 @@ struct LinkBuffer
|
|||
{
|
||||
/* Key: val, Value: idx in vec */
|
||||
QHash<T, int> hash;
|
||||
QVector<T> vec;
|
||||
std::vector<T> vec;
|
||||
|
||||
bool contains(T value)
|
||||
{
|
||||
return hash.contains(value);
|
||||
}
|
||||
|
||||
bool containsIdx(int idx)
|
||||
{
|
||||
if (vec.empty())
|
||||
return false;
|
||||
|
||||
return (idx < vec.size());
|
||||
}
|
||||
|
||||
int add(T value)
|
||||
{
|
||||
int idx = vec.count();
|
||||
int idx = vec.size();
|
||||
|
||||
hash.insert(value, idx);
|
||||
vec.append(value);
|
||||
vec.push_back(value);
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
@ -331,7 +339,7 @@ read_symlink(MarshalContext *ctx)
|
|||
{
|
||||
int idx = read_fixnum(ctx);
|
||||
|
||||
if (idx > ctx->symbols.vec.size()-1)
|
||||
if (!ctx->symbols.containsIdx(idx))
|
||||
throw Exception(Exception::ArgumentError, "bad symlink");
|
||||
|
||||
return ctx->symbols.lookup(idx);
|
||||
|
@ -342,7 +350,7 @@ read_link(MarshalContext *ctx)
|
|||
{
|
||||
int idx = read_fixnum(ctx);
|
||||
|
||||
if (idx > ctx->objects.vec.size()-1)
|
||||
if (!ctx->objects.containsIdx(idx))
|
||||
throw Exception(Exception::ArgumentError, "dump format error (unlinked)");
|
||||
|
||||
return ctx->objects.lookup(idx);
|
||||
|
|
|
@ -22,9 +22,10 @@
|
|||
#include "rwmem.h"
|
||||
|
||||
#include <SDL_rwops.h>
|
||||
#include <QVector>
|
||||
|
||||
typedef QVector<char> ByteVec;
|
||||
#include <vector>
|
||||
|
||||
typedef std::vector<char> ByteVec;
|
||||
|
||||
static inline ByteVec *
|
||||
getRWPrivate(SDL_RWops *ops)
|
||||
|
@ -62,7 +63,7 @@ static size_t SDL_RWopsWrite(SDL_RWops *ops, const void *buffer, size_t size, si
|
|||
if (writeBytes == 1)
|
||||
{
|
||||
char byte = *static_cast<const char*>(buffer);
|
||||
v->append(byte);
|
||||
v->push_back(byte);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -100,7 +101,7 @@ int RWMemGetData(SDL_RWops *ops, void *buffer)
|
|||
ByteVec *v = getRWPrivate(ops);
|
||||
|
||||
if (buffer)
|
||||
memcpy(buffer, v->constData(), v->size());
|
||||
memcpy(buffer, &(*v)[0], v->size());
|
||||
|
||||
return v->size();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue