Skip to content

Commit c48422c

Browse files
committed
cover.rs: remove most uses of suffixSize
1 parent b2c59d6 commit c48422c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/dictBuilder/cover.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ unsafe fn COVER_buildDictionary(
702702
let mut tail = dictBufferCapacity;
703703
let epochs = COVER_computeEpochs(
704704
dictBufferCapacity as u32,
705-
(*ctx).suffixSize as u32,
705+
(*ctx).suffixSize as u32, // suffix itself may be deallocated already
706706
parameters.k,
707707
4,
708708
);
@@ -842,7 +842,7 @@ pub unsafe extern "C" fn ZDICT_trainFromBuffer_cover(
842842
if ERR_isError(initVal) {
843843
return initVal;
844844
}
845-
COVER_warnOnSmallCorpus(dictBufferCapacity, ctx.suffixSize, displayLevel);
845+
COVER_warnOnSmallCorpus(dictBufferCapacity, ctx.suffix.len(), displayLevel);
846846
let mut activeDmers =
847847
COVER_map_t::new((parameters.k).wrapping_sub(parameters.d).wrapping_add(1));
848848
if displayLevel >= 2 {
@@ -1165,7 +1165,11 @@ unsafe fn COVER_tryParameters(opaque: *mut core::ffi::c_void) {
11651165
let totalCompressedSize = Error::GENERIC.to_error_code();
11661166
let dict = malloc(dictBufferCapacity) as *mut u8;
11671167
let mut selection = COVER_dictSelectionError(Error::GENERIC.to_error_code());
1168-
let freqs = malloc(((*ctx).suffixSize).wrapping_mul(::core::mem::size_of::<u32>())) as *mut u32;
1168+
let suffixSize = {
1169+
let suffix = &(*ctx).suffix;
1170+
suffix.len()
1171+
};
1172+
let freqs = malloc(suffixSize.wrapping_mul(::core::mem::size_of::<u32>())) as *mut u32;
11691173
let displayLevel = (*ctx).displayLevel;
11701174
let mut activeDmers =
11711175
COVER_map_t::new((parameters.k).wrapping_sub(parameters.d).wrapping_add(1));
@@ -1177,7 +1181,7 @@ unsafe fn COVER_tryParameters(opaque: *mut core::ffi::c_void) {
11771181
memcpy(
11781182
freqs as *mut core::ffi::c_void,
11791183
(*ctx).freqs.as_ptr() as *const core::ffi::c_void,
1180-
((*ctx).suffixSize).wrapping_mul(::core::mem::size_of::<u32>()),
1184+
(suffixSize).wrapping_mul(::core::mem::size_of::<u32>()),
11811185
);
11821186
let tail = COVER_buildDictionary(
11831187
ctx,
@@ -1355,7 +1359,7 @@ pub unsafe extern "C" fn ZDICT_optimizeTrainFromBuffer_cover(
13551359
return initVal;
13561360
}
13571361
if warned == 0 {
1358-
COVER_warnOnSmallCorpus(dictBufferCapacity, ctx.suffixSize, displayLevel);
1362+
COVER_warnOnSmallCorpus(dictBufferCapacity, ctx.suffix.len(), displayLevel);
13591363
warned = 1;
13601364
}
13611365
k = kMinK;

0 commit comments

Comments
 (0)