Use std::vector<BIT_VECTOR> for CLASS_STRUCT::Configurations

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2021-03-28 12:36:18 +02:00
parent 6f499f7fb5
commit 5bf1af257c
3 changed files with 12 additions and 31 deletions

View File

@ -60,9 +60,7 @@ int AddConfigToClass(CLASS_TYPE Class) {
NewNumConfigs =
(((Class->MaxNumConfigs + CONFIG_INCREMENT) / CONFIG_INCREMENT) * CONFIG_INCREMENT);
Class->Configurations =
static_cast<CONFIGS>(realloc(Class->Configurations, sizeof(BIT_VECTOR) * NewNumConfigs));
Class->Configurations.resize(NewNumConfigs);
Class->MaxNumConfigs = NewNumConfigs;
}
NewConfig = Class->NumConfigs++;
@ -131,15 +129,10 @@ void FreeClass(CLASS_TYPE Class) {
* Deallocate the memory consumed by subfields of the specified class.
**********************************************************************/
void FreeClassFields(CLASS_TYPE Class) {
int i;
if (Class) {
if (Class->MaxNumConfigs > 0) {
for (i = 0; i < Class->NumConfigs; i++) {
for (int i = 0; i < Class->NumConfigs; i++) {
FreeBitVector(Class->Configurations[i]);
}
free(Class->Configurations);
}
}
}
@ -154,13 +147,8 @@ CLASS_TYPE NewClass(int NumProtos, int NumConfigs) {
Class = new CLASS_STRUCT;
if (NumProtos > 0) {
Class->Prototypes.resize(NumProtos);
}
if (NumConfigs > 0) {
Class->Configurations = static_cast<CONFIGS>(malloc(NumConfigs * sizeof(BIT_VECTOR)));
}
Class->Configurations.resize(NumConfigs);
Class->MaxNumProtos = NumProtos;
Class->MaxNumConfigs = NumConfigs;
Class->NumProtos = 0;

View File

@ -27,8 +27,6 @@
namespace tesseract {
using CONFIGS = BIT_VECTOR *;
struct PROTO_STRUCT {
float A;
float B;
@ -40,18 +38,13 @@ struct PROTO_STRUCT {
};
struct CLASS_STRUCT {
CLASS_STRUCT()
: NumProtos(0)
, MaxNumProtos(0)
, NumConfigs(0)
, MaxNumConfigs(0)
, Configurations(nullptr) {}
int16_t NumProtos;
int16_t MaxNumProtos;
int16_t NumConfigs;
int16_t MaxNumConfigs;
CLASS_STRUCT() = default;
int16_t NumProtos = 0;
int16_t MaxNumProtos = 0;
int16_t NumConfigs = 0;
int16_t MaxNumConfigs = 0;
std::vector<PROTO_STRUCT> Prototypes;
CONFIGS Configurations;
std::vector<BIT_VECTOR> Configurations;
UnicityTable<int> font_set;
};
using CLASS_TYPE = CLASS_STRUCT *;

View File

@ -730,7 +730,7 @@ CLASS_STRUCT *SetUpForFloat2Int(const UNICHARSET &unicharset, LIST LabeledClassL
Class->NumConfigs = NumConfigs;
Class->MaxNumConfigs = NumConfigs;
Class->font_set.move(&font_set);
Class->Configurations = static_cast<BIT_VECTOR *>(malloc(sizeof(BIT_VECTOR) * NumConfigs));
Class->Configurations.resize(NumConfigs);
NumWords = WordsInVectorOfSize(NumProtos);
for (i = 0; i < NumConfigs; i++) {
NewConfig = NewBitVector(NumProtos);