mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
[ctree] create a new method appendbinfromhex
Summary: appendbinfromhex appends the binary representation of a 40-byte hex string onto a std::string. This allows us to reuse a std::string rather than to allocate a new one every time. Also: 1. converted binfromhex to use this method. 2. updated the docblocks to actually reflect reality. Test Plan: `make local && cd ~/work/fbsource && PYTHONPATH=~/work/mercurial/facebook-hg-rpms/remotefilelog:~/work/mercurial/facebook-hg-rpms/fb-hgext/:~/work/mercurial/facebook-hg-rpms/remotenames/:~/work/mercurial/facebook-hg-rpms/lz4revlog/ /opt/local/bin/python2.7 ~/work/mercurial/facebook-hg-rpms/hg-crew/hg --config extensions.perftest=~/work/mercurial/facebook-hg-rpms/remotefilelog/tests/perftest.py testtree --kind flat,ctree,fast --test fulliter,diff,find --build "master~5::master"` Reviewers: #fastmanifest, durham Reviewed By: durham Subscribers: mitrandir Differential Revision: https://phabricator.intern.facebook.com/D3770048 Signature: t1:3770048:1472105520:eac79a42360ebfa258519346b68fc4541c2dbb7c
This commit is contained in:
parent
a6bc389217
commit
79f0ebb34a
@ -34,16 +34,25 @@ static int8_t hextable[256] = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a given 20-byte node into a 40-byte hex string
|
||||
* Converts a given 40-byte hex string into a 20-byte node.
|
||||
*/
|
||||
inline void appendbinfromhex(const char *node, std::string &output) {
|
||||
for (int i = 0; i < 40;) {
|
||||
int8_t hi = hextable[(unsigned char)node[i++]];
|
||||
int8_t lo = hextable[(unsigned char)node[i++]];
|
||||
output.push_back((hi << 4) | lo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a given 40-byte hex string into a 20-byte node.
|
||||
*/
|
||||
inline std::string binfromhex(const char *node) {
|
||||
char binary[20];
|
||||
for (int i = 0; i < 40;) {
|
||||
int hi = hextable[(unsigned char)node[i++]];
|
||||
int lo = hextable[(unsigned char)node[i++]];
|
||||
binary[(i - 2) / 2] = (hi << 4) | lo;
|
||||
}
|
||||
return std::string(binary, 20);
|
||||
std::string result;
|
||||
|
||||
result.reserve(20);
|
||||
appendbinfromhex(node, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif //CTREEMANIFEST_CONVERT_H
|
||||
|
Loading…
Reference in New Issue
Block a user