From 18daa35a98afd7ba219509f607f5861f54a19b68 Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Thu, 1 Jun 2017 20:20:25 +0200 Subject: [PATCH 1/8] rbox-save.cpp: remove double check Signed-off-by: Danny Al-Gaaf --- src/storage-rbox/rbox-save.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage-rbox/rbox-save.cpp b/src/storage-rbox/rbox-save.cpp index ddf8b1c2..70831cd4 100644 --- a/src/storage-rbox/rbox-save.cpp +++ b/src/storage-rbox/rbox-save.cpp @@ -387,7 +387,7 @@ static int rbox_save_mail_write_metadata(struct dbox_save_context *ctx, struct d } static void remove_from_rados(librmb::RadosStorage *storage, char *oid) { - if (oid != 0 && storage != 0 && storage != 0) { + if (oid != 0 && storage != 0) { i_debug("object to delete is : %s", oid); (storage->get_io_ctx()).remove(oid); } From 6c39a2be2f0b763f82e381874db9bbc4403c3f5b Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Thu, 1 Jun 2017 20:26:15 +0200 Subject: [PATCH 2/8] rbox-save.cpp: fix unitialized var 'ret' Signed-off-by: Danny Al-Gaaf --- src/storage-rbox/rbox-save.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/storage-rbox/rbox-save.cpp b/src/storage-rbox/rbox-save.cpp index 70831cd4..42152906 100644 --- a/src/storage-rbox/rbox-save.cpp +++ b/src/storage-rbox/rbox-save.cpp @@ -181,8 +181,8 @@ off_t stream_mail_to_rados(const struct rbox_storage *storage, const std::string bl.clear(); bl.append((const char *)data); - int err = ((storage->s)->get_io_ctx()).write(oid, bl, iov.iov_len, offset); - if (err < 0) { + ret = ((storage->s)->get_io_ctx()).write(oid, bl, iov.iov_len, offset); + if (ret < 0) { return -1; } i_stream_skip(instream, 0); From ead6b0c49a111b1a1956eb6a5e89a73e0ae79a1c Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Thu, 1 Jun 2017 20:29:17 +0200 Subject: [PATCH 3/8] rados-cluster.cpp: prefer prefix ++/-- operator for non-primitiv types Prefix operators for non-primitiv types, it should be usually faster since it avoids creating a temporary copy. Signed-off-by: Danny Al-Gaaf --- src/librmb/rados-cluster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librmb/rados-cluster.cpp b/src/librmb/rados-cluster.cpp index 1f4ab766..3bff0342 100644 --- a/src/librmb/rados-cluster.cpp +++ b/src/librmb/rados-cluster.cpp @@ -102,7 +102,7 @@ int RadosCluster::storage_create(const string &pool, const string &username, Rad return err; } bool pool_found = false; - for (list>::iterator it = pool_list.begin(); it != pool_list.end(); it++) { + for (list>::iterator it = pool_list.begin(); it != pool_list.end(); ++it) { if ((*it).second.compare(pool) == 0) { pool_found = true; break; From 0328861267cd0ce6901689ffbdd20d57aedc5ec9 Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Thu, 1 Jun 2017 21:03:22 +0200 Subject: [PATCH 4/8] rados-dictionary.cpp: use compare() instead of find() In a condition the usage of string::find() is inefficient string::compare() would be faster. Signed-off-by: Danny Al-Gaaf --- src/librmb/rados-dictionary.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librmb/rados-dictionary.cpp b/src/librmb/rados-dictionary.cpp index ee2648ee..f12e8e85 100644 --- a/src/librmb/rados-dictionary.cpp +++ b/src/librmb/rados-dictionary.cpp @@ -36,9 +36,9 @@ RadosDictionary::RadosDictionary(librados::IoCtx *ctx, const string &username, c RadosDictionary::~RadosDictionary() { get_io_ctx().close(); } const string RadosDictionary::get_full_oid(const std::string &key) { - if (key.find(DICT_PATH_SHARED) == 0) { + if (!key.compare(0, strlen(DICT_PATH_SHARED), DICT_PATH_SHARED)) { return get_shared_oid(); - } else if (key.find(DICT_PATH_PRIVATE) == 0) { + } else if (!key.compare(0, strlen(DICT_PATH_PRIVATE), DICT_PATH_PRIVATE)) { return get_private_oid(); } else { // TODO(peter) i_unreached(); From 4eb1ba150cf5f5bb63e0888b2300328cb658d68f Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Thu, 1 Jun 2017 22:45:25 +0200 Subject: [PATCH 5/8] dict-rados.cpp: use compare() instead of find() Signed-off-by: Danny Al-Gaaf --- src/dict-rados/dict-rados.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/dict-rados/dict-rados.cpp b/src/dict-rados/dict-rados.cpp index e1185b5f..875d464c 100644 --- a/src/dict-rados/dict-rados.cpp +++ b/src/dict-rados/dict-rados.cpp @@ -324,10 +324,10 @@ class rados_dict_transaction_context { } ObjectWriteOperation &get_op(const std::string &key) { - if (key.find(DICT_PATH_SHARED) == 0) { + if (!key.compare(0, strlen(DICT_PATH_SHARED), DICT_PATH_SHARED)) { dirty_shared |= true; return write_op_shared; - } else if (key.find(DICT_PATH_PRIVATE) == 0) { + } else if (!key.compare(0, strlen(DICT_PATH_PRIVATE), DICT_PATH_PRIVATE)) { dirty_private |= true; return write_op_private; } @@ -335,17 +335,17 @@ class rados_dict_transaction_context { } void set_locked(const std::string &key) { - if (key.find(DICT_PATH_SHARED) == 0) { + if (!key.compare(0, strlen(DICT_PATH_SHARED), DICT_PATH_SHARED)) { locked_shared |= true; - } else if (key.find(DICT_PATH_PRIVATE) == 0) { + } else if (!key.compare(0, strlen(DICT_PATH_PRIVATE), DICT_PATH_PRIVATE)) { locked_private |= true; } } bool is_locked(const std::string &key) { - if (key.find(DICT_PATH_SHARED) == 0) { + if (!key.compare(0, strlen(DICT_PATH_SHARED), DICT_PATH_SHARED)) { return locked_shared; - } else if (key.find(DICT_PATH_PRIVATE) == 0) { + } else if (!key.compare(0, strlen(DICT_PATH_PRIVATE), DICT_PATH_PRIVATE)) { return locked_private; } i_unreached(); @@ -639,9 +639,9 @@ struct dict_iterate_context *rados_dict_iterate_init(struct dict *_dict, const c set shared_keys; while (*paths) { string key = *paths++; - if (key.find(DICT_PATH_SHARED) == 0) { + if (!key.compare(0, strlen(DICT_PATH_SHARED), DICT_PATH_SHARED)) { shared_keys.insert(key); - } else if (key.find(DICT_PATH_PRIVATE) == 0) { + } else if (!key.compare(0, strlen(DICT_PATH_PRIVATE), DICT_PATH_PRIVATE)) { private_keys.insert(key); } } From e526faf94c42272807daed56f389230311e34b9c Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Thu, 1 Jun 2017 23:04:36 +0200 Subject: [PATCH 6/8] rados-save.cpp: fix UNINIT_CTOR Signed-off-by: Danny Al-Gaaf --- src/storage-rados/rados-save.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/storage-rados/rados-save.cpp b/src/storage-rados/rados-save.cpp index 58f29b7c..027b1990 100644 --- a/src/storage-rados/rados-save.cpp +++ b/src/storage-rados/rados-save.cpp @@ -37,7 +37,12 @@ using std::string; class rados_save_context { public: - explicit rados_save_context(RadosStorage &rados_storage) : rados_storage(rados_storage) {} + explicit rados_save_context(RadosStorage &rados_storage) : mbox(NULL), trans(NULL), + mail_count(0), sync_ctx(NULL), + seq(0), input(NULL), + rados_storage(rados_storage), + mailObject(NULL), failed(1), + finished(1) {} struct mail_save_context ctx; From 2a6a5013779780c4269d35d7b34859d8858fad8f Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Thu, 1 Jun 2017 23:07:53 +0200 Subject: [PATCH 7/8] rados-save.cpp: remove unused variables Signed-off-by: Danny Al-Gaaf --- src/storage-rados/rados-save.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/storage-rados/rados-save.cpp b/src/storage-rados/rados-save.cpp index 027b1990..e8136168 100644 --- a/src/storage-rados/rados-save.cpp +++ b/src/storage-rados/rados-save.cpp @@ -322,11 +322,6 @@ int rados_transaction_save_commit_pre(struct mail_save_context *_ctx) { struct mailbox_transaction_context *_t = _ctx->transaction; const struct mail_index_header *hdr; struct seq_range_iter iter; - uint32_t uid; - const char *dir; - string_t *src_path, *dest_path; - unsigned int n; - size_t src_prefixlen, dest_prefixlen; i_assert(ctx->finished); From f5f48ad507ba5c74865f99bddf813373cc19199c Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Thu, 1 Jun 2017 23:16:29 +0200 Subject: [PATCH 8/8] rbox-mail.cpp: remove unused var Signed-off-by: Danny Al-Gaaf --- src/storage-rbox/rbox-mail.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/storage-rbox/rbox-mail.cpp b/src/storage-rbox/rbox-mail.cpp index a5460edc..7037cec6 100644 --- a/src/storage-rbox/rbox-mail.cpp +++ b/src/storage-rbox/rbox-mail.cpp @@ -274,7 +274,6 @@ static int rbox_mail_get_physical_size(struct mail *_mail, uoff_t *size_r) { FUNC_START(); struct dbox_mail *mail = (struct dbox_mail *)_mail; struct index_mail_data *data = &mail->imail.data; - struct dbox_file *file; struct rbox_storage *rbox_storage = (struct rbox_storage *)_mail->box->storage; uint64_t file_size;