Commit 830530e3 authored by Marc Vef's avatar Marc Vef
Browse files

Optimization: Replace to_string with fmt::FormatInt

parent 2ccf944a
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ using namespace std;
 */
bool init_dentry_dir(const fuse_ino_t inode) {
    auto d_path = bfs::path(ADAFS_DATA->dentry_path());
    d_path /= to_string(inode);
    d_path /= fmt::FormatInt(inode).c_str();
    bfs::create_directories(d_path);
    // XXX This might not be needed as it is another access to the underlying file system
//    return bfs::exists(d_path);
@@ -31,7 +31,7 @@ bool init_dentry_dir(const fuse_ino_t inode) {
 */
int destroy_dentry_dir(const fuse_ino_t inode) {
    auto d_path = bfs::path(ADAFS_DATA->dentry_path());
    d_path /= to_string(inode);
    d_path /= fmt::FormatInt(inode).c_str();

    // remove dentry dir
    bfs::remove_all(d_path);
@@ -55,10 +55,10 @@ bool verify_dentry(const fuse_ino_t inode) {
//
//
//    if (inode.has_parent_path()) { // non-root
//        d_path /= to_string(ADAFS_DATA->hashf(inode.parent_path().string()));
//        d_path /= fmt::FormatInt(ADAFS_DATA->hashf(inode.parent_path().string()));
//        d_path /= inode.filename(); // root
//    } else {
//        d_path /= to_string(ADAFS_DATA->hashf(inode.string()));
//        d_path /= fmt::FormatInt(ADAFS_DATA->hashf(inode.string()));
//    }
//    // if file path exists leaf name is a valid dentry of parent_dir
//    return bfs::exists(d_path);
@@ -71,7 +71,7 @@ bool verify_dentry(const fuse_ino_t inode) {
 */
int read_dentries(const fuse_ino_t p_inode, const fuse_ino_t inode) {
//    auto path = bfs::path(ADAFS_DATA->dentry_path());
//    path /= to_string(inode);
//    path /= fmt::FormatInt(inode);
//    if (!bfs::exists(path)) return 1;
//    // shortcut if path is empty = no files in directory
//    if (bfs::is_empty(path)) return 0;
@@ -95,7 +95,7 @@ int read_dentries(const fuse_ino_t p_inode, const fuse_ino_t inode) {
int get_dentries(vector<Dentry>& dentries, const fuse_ino_t dir_inode) {
    ADAFS_DATA->spdlogger()->debug("get_dentries: inode {}", dir_inode);
    auto d_path = bfs::path(ADAFS_DATA->dentry_path());
    d_path /= to_string(dir_inode);
    d_path /= fmt::FormatInt(dir_inode).c_str();
    // shortcut if path is empty = no files in directory
    if (bfs::is_empty(d_path)) return 0;

@@ -133,7 +133,7 @@ pair<int, fuse_ino_t> do_lookup(fuse_req_t& req, const fuse_ino_t p_inode, const
    // XXX error handling
    // TODO look into cache first
    auto d_path = bfs::path(ADAFS_DATA->dentry_path());
    d_path /= to_string(p_inode);
    d_path /= fmt::FormatInt(p_inode).c_str();
    // XXX check if this is needed later
    d_path /= name;
    if (!bfs::exists(d_path))
@@ -158,7 +158,7 @@ int create_dentry(const fuse_ino_t p_inode, const fuse_ino_t inode, const string
//    ADAFS_DATA->logger->debug("create_dentry() enter with fname: {}", inode);
    // XXX Errorhandling
    auto d_path = bfs::path(ADAFS_DATA->dentry_path());
    d_path /= to_string(p_inode);
    d_path /= fmt::FormatInt(p_inode).c_str();
    // XXX check if this is needed later
//    if (!bfs::exists(d_path)) return -ENOENT;

@@ -186,7 +186,7 @@ int create_dentry(const fuse_ino_t p_inode, const fuse_ino_t inode, const string
pair<int, fuse_ino_t> remove_dentry(const fuse_ino_t p_inode, const string &name) {
    int inode; // file inode to be read from dentry before deletion
    auto d_path = bfs::path(ADAFS_DATA->dentry_path());
    d_path /= to_string(p_inode);
    d_path /= fmt::FormatInt(p_inode).c_str();
    d_path /= name;

    // retrieve inode number of dentry
@@ -208,7 +208,7 @@ pair<int, fuse_ino_t> remove_dentry(const fuse_ino_t p_inode, const string &name
 */
int is_dir_empty(const fuse_ino_t inode) {
    auto d_path = bfs::path(ADAFS_DATA->dentry_path());
    d_path /= to_string(inode);
    d_path /= fmt::FormatInt(inode).c_str();
    if (bfs::is_empty(d_path))
        return 0;
    else
+2 −2
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ int get_metadata(Metadata& md, const fuse_ino_t inode) {
    ADAFS_DATA->spdlogger()->debug("get_metadata() enter for inode {}", inode);
    // Verify that the file's inode exists
    auto path = bfs::path(ADAFS_DATA->inode_path());
    path /= to_string(inode);
    path /= fmt::FormatInt(inode).c_str();
    if (bfs::exists(path)) {
        read_all_metadata(md, inode);
        return 0;
@@ -98,7 +98,7 @@ void metadata_to_stat(const Metadata& md, struct stat& attr) {
int remove_metadata(const fuse_ino_t inode) {
    // XXX Errorhandling
    auto i_path = bfs::path(ADAFS_DATA->inode_path());
    i_path /= to_string(inode);
    i_path /= fmt::FormatInt(inode).c_str();

    bfs::remove_all(i_path);
    // XXX make sure metadata has been deleted
+2 −2
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ bool write_all_metadata(const Metadata& md, const fuse_ino_t inode);
template<typename T>
bool write_metadata_field(const T& field, const string& field_name, const fuse_ino_t inode) {
    auto i_path = bfs::path(ADAFS_DATA->inode_path());
    i_path /= to_string(inode);
    i_path /= fmt::FormatInt(inode).c_str();
    bfs::create_directories(i_path);
    i_path /= field_name;

@@ -54,7 +54,7 @@ bool read_all_metadata(Metadata& md, const fuse_ino_t inode);
template<typename T>
unique_ptr<T> read_metadata_field(const string& field_name, const fuse_ino_t inode) {
    auto path = bfs::path(ADAFS_DATA->inode_path());
    path /= to_string(inode);
    path /= fmt::FormatInt(inode).c_str();
    path /= field_name;
    if (!bfs::exists(path)) return nullptr;

+2 −2
Original line number Diff line number Diff line
@@ -8,12 +8,12 @@
// To enabled logging with info level
//#define LOG_INFO
//#define LOG_DEBUG
#define LOG_TRACE
//#define LOG_TRACE

// If ACM time should be considered
#define ACMtime

// If access permissions should be checked while opening a file
#define CHECK_ACCESS
//#define CHECK_ACCESS

#endif //FS_CONFIGURE_H
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include "configure.h"
#include "spdlog/spdlog.h"
#include "spdlog/fmt/fmt.h"
#include "classes/fs_data.h"

namespace bfs = boost::filesystem;