Skip to content

Commit

Permalink
got rid of mutex in destructor, made global name longer
Browse files Browse the repository at this point in the history
  • Loading branch information
wjblanke authored and hoffmang9 committed Feb 24, 2021
1 parent 55a8838 commit a252a5b
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/encoding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class TMemoCache {
~TMemoCache()
{
// Clean up global entries on destruction
std::lock_guard<std::mutex> l(memoMutex);

std::map<double, FSE_CTable *>::iterator itc;
for (itc = CT_MEMO.begin(); itc != CT_MEMO.end(); itc++) {
FSE_freeCTable(itc->second);
Expand Down Expand Up @@ -90,7 +88,7 @@ class TMemoCache {
std::map<double, FSE_DTable *> DT_MEMO;
};

TMemoCache tmc;
TMemoCache tmCache;

class Encoding {
public:
Expand Down Expand Up @@ -182,7 +180,7 @@ class Encoding {

static size_t ANSEncodeDeltas(std::vector<unsigned char> deltas, double R, uint8_t *out)
{
if (!tmc.CTExists(R)) {
if (!tmCache.CTExists(R)) {
std::vector<short> nCount = Encoding::CreateNormalizedCount(R);
unsigned maxSymbolValue = nCount.size() - 1;
unsigned tableLog = 14;
Expand All @@ -194,10 +192,10 @@ class Encoding {
if (FSE_isError(err)) {
throw FSE_getErrorName(err);
}
tmc.CTAssign(R, ct);
tmCache.CTAssign(R, ct);
}

FSE_CTable *ct = tmc.CTGet(R);
FSE_CTable *ct = tmCache.CTGet(R);
return FSE_compress_usingCTable(
out, deltas.size() * 8, static_cast<void *>(deltas.data()), deltas.size(), ct);
}
Expand All @@ -213,7 +211,7 @@ class Encoding {
int numDeltas,
double R)
{
if (!tmc.DTExists(R)) {
if (!tmCache.DTExists(R)) {
std::vector<short> nCount = Encoding::CreateNormalizedCount(R);
unsigned maxSymbolValue = nCount.size() - 1;
unsigned tableLog = 14;
Expand All @@ -223,10 +221,10 @@ class Encoding {
if (FSE_isError(err)) {
throw FSE_getErrorName(err);
}
tmc.DTAssign(R, dt);
tmCache.DTAssign(R, dt);
}

FSE_DTable *dt = tmc.DTGet(R);
FSE_DTable *dt = tmCache.DTGet(R);

std::vector<uint8_t> deltas(numDeltas);
size_t err = FSE_decompress_usingDTable(&deltas[0], numDeltas, inp, inp_size, dt);
Expand Down

0 comments on commit a252a5b

Please sign in to comment.