pmem / pmemkv

Key/Value Datastore for Persistent Memory
https://pmem.io
Other
398 stars 119 forks source link

Duplication reported by PMD tool #1034

Open KFilipek opened 3 years ago

KFilipek commented 3 years ago

ISSUE: Duplication reported by PMD tool

Environment Information

Name Version
pmemkv version(s) 54f2660003fc597
libpmemobj-cpp version(s) N/A
PMDK (libpmem/libpmemobj) version(s) N/A
OS(es) version(s) N/A
kernel version(s) N/A
compiler, libraries, packaging and other related tools version(s) N/A

Please provide a reproduction of the bug:

./bin/run.sh cpd --minimum-tokens 100 --files ~/Development/work/pmemkv/src/ --language cpp

Details

I removed API related duplications.

Found a 22 line (172 tokens) duplication in the following files: 
Starting at line 1918 of /home/kfilipek/Development/work/pmemkv/src/engines-experimental/stree/persistent_b_tree.h
Starting at line 1960 of /home/kfilipek/Development/work/pmemkv/src/engines-experimental/stree/persistent_b_tree.h

b_tree_base<Key, T, Compare, degree>::split_leaf_node(pool_base &pop,
                              leaf_pptr &split_leaf, K &&key,
                              M &&obj)
{
    assert(split_leaf->full());

    leaf_pptr node;
    std::pair<iterator, bool> result(nullptr, false);
    auto middle = split_leaf->begin() + split_leaf->size() / 2;
    bool less = compare(std::forward<K>(key), middle->first);
    // move second half into node and insert new element where needed
    pmem::obj::transaction::run(pop, [&] {
        node = allocate_leaf();
        node->move(pop, split_leaf, compare);
        /* insert entry(key, obj) into needed half */
        if (less) {
            result = internal_insert(split_leaf, std::forward<K>(key),
                         std::forward<M>(obj));
        } else {
            result = internal_insert(node, std::forward<K>(key),
                         std::forward<M>(obj));
        }