Project

General

Profile

Actions

Bug #4826

closed

IBLT::getHashTable() makes unnecesary copy

Added by Anonymous almost 6 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Low
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

IBLT::getHashTable() is defined as:
https://github.com/named-data/PSync/blob/0cf4b600e91455ee07c38eb22876aa6b653bc14b/PSync/detail/iblt.hpp#L129

std::vector<HashTableEntry> getHashTable() const { return m_hashTable; }

I believe this returns a copy of the entire m_hashTable vector. For read-only, it would be more efficient to return a reference:

const std::vector<HashTableEntry>& getHashTable() const { return m_hashTable; }

Likewise, operator== gets the hash table:
https://github.com/named-data/PSync/blob/0cf4b600e91455ee07c38eb22876aa6b653bc14b/PSync/detail/iblt.cpp#L190

auto iblt1HashTable = iblt1.getHashTable();

I think this makes a copy of the entire hash table vector. Even if getHashTable() is changed to return a reference, I'm not sure whether auto would be a vector or a vector reference. (If it is a vector, then it will still make a copy.) Maybe it's clearer and safer to use auto& :

auto& iblt1HashTable = iblt1.getHashTable();

(This is a low-priority observation. Feel free to ignore it if you want.)

Actions #1

Updated by Davide Pesavento almost 3 years ago

  • Tracker changed from Task to Bug
  • Status changed from New to Closed
  • Assignee set to Ashlesh Gawande
  • Start date deleted (01/29/2019)

Fixed in commit d51690accfdca48c0b38b6f6e646741c9460f527

Actions #2

Updated by Davide Pesavento almost 3 years ago

  • Target version set to v0.2.0
Actions

Also available in: Atom PDF