Project

General

Profile

Task #4826

IBLT::getHashTable() makes unnecesary copy

Added by Jeff Thompson 7 months ago.

Status:
New
Priority:
Low
Assignee:
-
Target version:
-
Start date:
01/29/2019
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.)

Also available in: Atom PDF