[gnote] Replace std::list with std::vector in isyncmanager
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Replace std::list with std::vector in isyncmanager
- Date: Sat, 27 Apr 2019 16:56:39 +0000 (UTC)
commit 53737cbe2f19e733572f6f37e372d189261b29e3
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sat Apr 27 19:30:29 2019 +0300
Replace std::list with std::vector in isyncmanager
src/synchronization/filesystemsyncserver.cpp | 22 +++++++++++-----------
src/synchronization/filesystemsyncserver.hpp | 10 +++++-----
src/synchronization/isyncmanager.hpp | 8 +++-----
src/synchronization/syncmanager.cpp | 11 +++++------
4 files changed, 24 insertions(+), 27 deletions(-)
---
diff --git a/src/synchronization/filesystemsyncserver.cpp b/src/synchronization/filesystemsyncserver.cpp
index abe8510e..5a725fd5 100644
--- a/src/synchronization/filesystemsyncserver.cpp
+++ b/src/synchronization/filesystemsyncserver.cpp
@@ -98,35 +98,35 @@ void FileSystemSyncServer::common_ctor()
}
-void FileSystemSyncServer::upload_notes(const std::list<Note::Ptr> & notes)
+void FileSystemSyncServer::upload_notes(const std::vector<Note::Ptr> & notes)
{
if(sharp::directory_exists(m_new_revision_path) == false) {
sharp::directory_create(m_new_revision_path);
}
DBG_OUT("UploadNotes: notes.Count = %d", int(notes.size()));
- for(std::list<Note::Ptr>::const_iterator iter = notes.begin(); iter != notes.end(); ++iter) {
+ for(auto & iter : notes) {
try {
- auto server_note = m_new_revision_path->get_child(sharp::file_filename((*iter)->file_path()));
- auto local_note = Gio::File::create_for_path((*iter)->file_path());
+ auto server_note = m_new_revision_path->get_child(sharp::file_filename(iter->file_path()));
+ auto local_note = Gio::File::create_for_path(iter->file_path());
local_note->copy(server_note);
- m_updated_notes.push_back(sharp::file_basename((*iter)->file_path()));
+ m_updated_notes.push_back(sharp::file_basename(iter->file_path()));
}
catch(...) {
- DBG_OUT("Sync: Error uploading note \"%s\"", (*iter)->get_title().c_str());
+ DBG_OUT("Sync: Error uploading note \"%s\"", iter->get_title().c_str());
}
}
}
-void FileSystemSyncServer::delete_notes(const std::list<Glib::ustring> & deletedNoteUUIDs)
+void FileSystemSyncServer::delete_notes(const std::vector<Glib::ustring> & deletedNoteUUIDs)
{
m_deleted_notes.insert(m_deleted_notes.end(), deletedNoteUUIDs.begin(), deletedNoteUUIDs.end());
}
-std::list<Glib::ustring> FileSystemSyncServer::get_all_note_uuids()
+std::vector<Glib::ustring> FileSystemSyncServer::get_all_note_uuids()
{
- std::list<Glib::ustring> noteUUIDs;
+ std::vector<Glib::ustring> noteUUIDs;
xmlDocPtr xml_doc = NULL;
if(is_valid_xml_file(m_manifest_path, &xml_doc)) {
@@ -309,9 +309,9 @@ bool FileSystemSyncServer::commit_sync_transaction()
}
// Write out all the updated notes
- for(std::list<Glib::ustring>::iterator iter = m_updated_notes.begin(); iter != m_updated_notes.end();
++iter) {
+ for(auto & note : m_updated_notes) {
xml->write_start_element("", "note", "");
- xml->write_attribute_string("", "id", "", *iter);
+ xml->write_attribute_string("", "id", "", note);
xml->write_attribute_string("", "rev", "", TO_STRING(m_new_revision));
xml->write_end_element();
}
diff --git a/src/synchronization/filesystemsyncserver.hpp b/src/synchronization/filesystemsyncserver.hpp
index 53200f16..5d0c1205 100644
--- a/src/synchronization/filesystemsyncserver.hpp
+++ b/src/synchronization/filesystemsyncserver.hpp
@@ -39,10 +39,10 @@ public:
virtual bool begin_sync_transaction() override;
virtual bool commit_sync_transaction() override;
virtual bool cancel_sync_transaction() override;
- virtual std::list<Glib::ustring> get_all_note_uuids() override;
+ virtual std::vector<Glib::ustring> get_all_note_uuids() override;
virtual std::map<Glib::ustring, NoteUpdate> get_note_updates_since(int revision) override;
- virtual void delete_notes(const std::list<Glib::ustring> & deletedNoteUUIDs) override;
- virtual void upload_notes(const std::list<Note::Ptr> & notes) override;
+ virtual void delete_notes(const std::vector<Glib::ustring> & deletedNoteUUIDs) override;
+ virtual void upload_notes(const std::vector<Note::Ptr> & notes) override;
virtual int latest_revision() override; // NOTE: Only reliable during a transaction
virtual SyncLockInfo current_sync_lock() override;
virtual Glib::ustring id() override;
@@ -58,8 +58,8 @@ private:
bool is_valid_xml_file(const Glib::RefPtr<Gio::File> & xmlFilePath, xmlDocPtr *xml_doc);
void lock_timeout();
- std::list<Glib::ustring> m_updated_notes;
- std::list<Glib::ustring> m_deleted_notes;
+ std::vector<Glib::ustring> m_updated_notes;
+ std::vector<Glib::ustring> m_deleted_notes;
Glib::ustring m_server_id;
diff --git a/src/synchronization/isyncmanager.hpp b/src/synchronization/isyncmanager.hpp
index c7b30848..90d0ecda 100644
--- a/src/synchronization/isyncmanager.hpp
+++ b/src/synchronization/isyncmanager.hpp
@@ -21,8 +21,6 @@
#ifndef _SYNCHRONIZATION_ISYNCMANAGER_HPP_
#define _SYNCHRONIZATION_ISYNCMANAGER_HPP_
-#include <list>
-
#include "note.hpp"
#include "syncui.hpp"
#include "syncutils.hpp"
@@ -86,10 +84,10 @@ public:
virtual bool begin_sync_transaction() = 0;
virtual bool commit_sync_transaction() = 0;
virtual bool cancel_sync_transaction() = 0;
- virtual std::list<Glib::ustring> get_all_note_uuids() = 0;
+ virtual std::vector<Glib::ustring> get_all_note_uuids() = 0;
virtual std::map<Glib::ustring, NoteUpdate> get_note_updates_since(int revision) = 0;
- virtual void delete_notes(const std::list<Glib::ustring> & deletedNoteUUIDs) = 0;
- virtual void upload_notes(const std::list<Note::Ptr> & notes) = 0;
+ virtual void delete_notes(const std::vector<Glib::ustring> & deletedNoteUUIDs) = 0;
+ virtual void upload_notes(const std::vector<Note::Ptr> & notes) = 0;
virtual int latest_revision() = 0; // NOTE: Only reliable during a transaction
virtual SyncLockInfo current_sync_lock() = 0;
virtual Glib::ustring id() = 0;
diff --git a/src/synchronization/syncmanager.cpp b/src/synchronization/syncmanager.cpp
index 6d733d36..90570157 100644
--- a/src/synchronization/syncmanager.cpp
+++ b/src/synchronization/syncmanager.cpp
@@ -292,7 +292,7 @@ namespace sync {
set_state(PREPARE_UPLOAD);
// Look through all the notes modified on the client
// and upload new or modified ones to the server
- std::list<Note::Ptr> newOrModifiedNotes;
+ std::vector<Note::Ptr> newOrModifiedNotes;
for(const NoteBase::Ptr & iter : note_mgr().get_notes()) {
Note::Ptr note = std::static_pointer_cast<Note>(iter);
if(m_client->get_revision(note) == -1) {
@@ -321,8 +321,8 @@ namespace sync {
}
// Handle notes deleted on client
- std::list<Glib::ustring> locallyDeletedUUIDs;
- std::list<Glib::ustring> all_note_uuids = server->get_all_note_uuids();
+ std::vector<Glib::ustring> locallyDeletedUUIDs;
+ auto all_note_uuids = server->get_all_note_uuids();
for(auto & iter : all_note_uuids) {
if(find_note_by_uuid(iter) == 0) {
locallyDeletedUUIDs.push_back(iter);
@@ -346,9 +346,8 @@ namespace sync {
if(commitResult) {
// Apply this revision number to all new/modified notes since last sync
// TODO: Is this the best place to do this (after successful server commit)
- for(std::list<Note::Ptr>::iterator iter = newOrModifiedNotes.begin();
- iter != newOrModifiedNotes.end(); ++iter) {
- m_client->set_revision(*iter, newRevision);
+ for(auto & iter : newOrModifiedNotes) {
+ m_client->set_revision(iter, newRevision);
}
set_state(SUCCEEDED);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]