int _begin = 0;
int _size = -1;
+ /* Pointer to the beginning of the data. WARNING: not null terminated */
+ const char *data() const { return _arr.constData() + _begin; }
+ friend struct ByteArrayRefHash;
+
public:
- ByteArrayRef(const QByteArray &arr = {}, int begin = 0, int size = -1)
- : _arr(arr)
+ ByteArrayRef(QByteArray arr = {}, int begin = 0, int size = -1)
+ : _arr(std::move(arr))
, _begin(begin)
- , _size(qMin(arr.size() - begin, size < 0 ? arr.size() : size))
+ , _size(qMin(_arr.size() - begin, size < 0 ? _arr.size() - begin : size))
{
}
ByteArrayRef left(int l) const { return ByteArrayRef(_arr, _begin, l); };
char at(int x) const { return _arr.at(_begin + x); }
int size() const { return _size; }
- /* Pointer to the beginning of the data. WARNING: not null terminated */
- const char *data() const { return _arr.constData() + _begin; }
+ int length() const { return _size; }
+ bool isEmpty() const { return _size == 0; }
friend bool operator==(const ByteArrayRef &a, const ByteArrayRef &b)
{ return a.size() == b.size() && qstrncmp(a.data(), b.data(), a.size()) == 0; }
};
+struct ByteArrayRefHash { uint operator()(const ByteArrayRef &a) const { return qHashBits(a.data(), a.size()); } };
/**
* @brief csync public structure
*/
struct OCSYNC_EXPORT csync_s {
- struct FileMapHash { uint operator()(const ByteArrayRef &a) const { return qHashBits(a.data(), a.size()); } };
- class FileMap : public std::unordered_map<ByteArrayRef, std::unique_ptr<csync_file_stat_t>, FileMapHash> {
+
+ class FileMap : public std::unordered_map<ByteArrayRef, std::unique_ptr<csync_file_stat_t>, ByteArrayRefHash> {
public:
csync_file_stat_t *findFile(const ByteArrayRef &key) const {
auto it = find(key);
OCC::SyncJournalDb *statedb;
struct {
- std::map<QByteArray, QByteArray> folder_renamed_to; // map from->to
- std::map<QByteArray, QByteArray> folder_renamed_from; // map to->from
+ std::unordered_map<ByteArrayRef, QByteArray, ByteArrayRefHash> folder_renamed_to; // map from->to
+ std::unordered_map<ByteArrayRef, QByteArray, ByteArrayRefHash> folder_renamed_from; // map to->from
} renames;
struct {
#include <algorithm>
-static QByteArray _parentDir(const QByteArray &path) {
+static ByteArrayRef _parentDir(const ByteArrayRef &path) {
int len = path.length();
while(len > 0 && path.at(len-1)!='/') len--;
while(len > 0 && path.at(len-1)=='/') len--;
QByteArray csync_rename_adjust_path(CSYNC* ctx, const QByteArray &path)
{
- for (QByteArray p = _parentDir(path); !p.isEmpty(); p = _parentDir(p)) {
- std::map< QByteArray, QByteArray >::iterator it = ctx->renames.folder_renamed_to.find(p);
+ if (ctx->renames.folder_renamed_to.empty())
+ return path;
+ for (auto p = _parentDir(path); !p.isEmpty(); p = _parentDir(p)) {
+ auto it = ctx->renames.folder_renamed_to.find(p);
if (it != ctx->renames.folder_renamed_to.end()) {
QByteArray rep = it->second + path.mid(p.length());
return rep;
QByteArray csync_rename_adjust_path_source(CSYNC* ctx, const QByteArray &path)
{
- for (QByteArray p = _parentDir(path); !p.isEmpty(); p = _parentDir(p)) {
- std::map< QByteArray, QByteArray >::iterator it = ctx->renames.folder_renamed_from.find(p);
+ if (ctx->renames.folder_renamed_from.empty())
+ return path;
+ for (auto p = _parentDir(path); !p.isEmpty(); p = _parentDir(p)) {
+ auto it = ctx->renames.folder_renamed_from.find(p);
if (it != ctx->renames.folder_renamed_from.end()) {
QByteArray rep = it->second + path.mid(p.length());
return rep;