mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-24 02:59:07 +08:00
Initialize variables in initialization list
This fixes several performance issues reported by Coverity: Variable 'master_trainer_' is assigned in constructor body. Consider performing initialization in initialization list. Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
4ea8495d1c
commit
6be58e54fa
@ -39,12 +39,9 @@ static const char kIllegalUnicharMsg[] = "Illegal unichar %s in ambiguity specif
|
|||||||
// UNICHAR_LEN * (MAX_AMBIG_SIZE + 1) for each part of the ambig
|
// UNICHAR_LEN * (MAX_AMBIG_SIZE + 1) for each part of the ambig
|
||||||
const int kMaxAmbigStringSize = UNICHAR_LEN * (MAX_AMBIG_SIZE + 1);
|
const int kMaxAmbigStringSize = UNICHAR_LEN * (MAX_AMBIG_SIZE + 1);
|
||||||
|
|
||||||
AmbigSpec::AmbigSpec() {
|
AmbigSpec::AmbigSpec() : correct_ngram_id(INVALID_UNICHAR_ID), type(NOT_AMBIG), wrong_ngram_size(0) {
|
||||||
wrong_ngram[0] = INVALID_UNICHAR_ID;
|
wrong_ngram[0] = INVALID_UNICHAR_ID;
|
||||||
correct_fragments[0] = INVALID_UNICHAR_ID;
|
correct_fragments[0] = INVALID_UNICHAR_ID;
|
||||||
correct_ngram_id = INVALID_UNICHAR_ID;
|
|
||||||
type = NOT_AMBIG;
|
|
||||||
wrong_ngram_size = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializes the ambigs by adding a nullptr pointer to each table.
|
// Initializes the ambigs by adding a nullptr pointer to each table.
|
||||||
|
@ -59,13 +59,12 @@ PERM_CONFIG_STRUCT::~PERM_CONFIG_STRUCT() {
|
|||||||
delete[] Ambigs;
|
delete[] Ambigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
ADAPT_CLASS_STRUCT::ADAPT_CLASS_STRUCT() {
|
ADAPT_CLASS_STRUCT::ADAPT_CLASS_STRUCT() :
|
||||||
NumPermConfigs = 0;
|
NumPermConfigs(0),
|
||||||
MaxNumTimesSeen = 0;
|
MaxNumTimesSeen(0),
|
||||||
TempProtos = NIL_LIST;
|
PermProtos(NewBitVector(MAX_NUM_PROTOS)),
|
||||||
|
PermConfigs(NewBitVector(MAX_NUM_CONFIGS)),
|
||||||
PermProtos = NewBitVector(MAX_NUM_PROTOS);
|
TempProtos(NIL_LIST) {
|
||||||
PermConfigs = NewBitVector(MAX_NUM_CONFIGS);
|
|
||||||
zero_all_bits(PermProtos, WordsInVectorOfSize(MAX_NUM_PROTOS));
|
zero_all_bits(PermProtos, WordsInVectorOfSize(MAX_NUM_PROTOS));
|
||||||
zero_all_bits(PermConfigs, WordsInVectorOfSize(MAX_NUM_CONFIGS));
|
zero_all_bits(PermConfigs, WordsInVectorOfSize(MAX_NUM_CONFIGS));
|
||||||
|
|
||||||
@ -124,16 +123,13 @@ int Classify::GetFontinfoId(ADAPT_CLASS_STRUCT *Class, uint8_t ConfigId) {
|
|||||||
///
|
///
|
||||||
/// @param MaxProtoId max id of any proto in new config
|
/// @param MaxProtoId max id of any proto in new config
|
||||||
/// @param FontinfoId font information from pre-trained templates
|
/// @param FontinfoId font information from pre-trained templates
|
||||||
TEMP_CONFIG_STRUCT::TEMP_CONFIG_STRUCT(int maxProtoId, int fontinfoId) {
|
TEMP_CONFIG_STRUCT::TEMP_CONFIG_STRUCT(int maxProtoId, int fontinfoId) :
|
||||||
int NumProtos = maxProtoId + 1;
|
NumTimesSeen(1),
|
||||||
|
ProtoVectorSize(WordsInVectorOfSize(maxProtoId + 1)),
|
||||||
Protos = NewBitVector(NumProtos);
|
MaxProtoId(maxProtoId),
|
||||||
|
Protos(NewBitVector(maxProtoId + 1)),
|
||||||
NumTimesSeen = 1;
|
FontinfoId(fontinfoId) {
|
||||||
MaxProtoId = maxProtoId;
|
|
||||||
ProtoVectorSize = WordsInVectorOfSize(NumProtos);
|
|
||||||
zero_all_bits(Protos, ProtoVectorSize);
|
zero_all_bits(Protos, ProtoVectorSize);
|
||||||
FontinfoId = fontinfoId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMP_CONFIG_STRUCT::~TEMP_CONFIG_STRUCT() {
|
TEMP_CONFIG_STRUCT::~TEMP_CONFIG_STRUCT() {
|
||||||
|
@ -78,8 +78,8 @@ static void Win32WarningHandler(const char *module, const char *fmt, va_list ap)
|
|||||||
|
|
||||||
class AutoWin32ConsoleOutputCP {
|
class AutoWin32ConsoleOutputCP {
|
||||||
public:
|
public:
|
||||||
explicit AutoWin32ConsoleOutputCP(UINT codeCP) {
|
explicit AutoWin32ConsoleOutputCP(UINT codeCP) :
|
||||||
oldCP_ = GetConsoleOutputCP();
|
oldCP_(GetConsoleOutputCP()) {
|
||||||
SetConsoleOutputCP(codeCP);
|
SetConsoleOutputCP(codeCP);
|
||||||
}
|
}
|
||||||
~AutoWin32ConsoleOutputCP() {
|
~AutoWin32ConsoleOutputCP() {
|
||||||
|
@ -38,15 +38,16 @@ INT_VAR(devanagari_split_debuglevel, 0, "Debug level for split shiro-rekha proce
|
|||||||
BOOL_VAR(devanagari_split_debugimage, 0,
|
BOOL_VAR(devanagari_split_debugimage, 0,
|
||||||
"Whether to create a debug image for split shiro-rekha process.");
|
"Whether to create a debug image for split shiro-rekha process.");
|
||||||
|
|
||||||
ShiroRekhaSplitter::ShiroRekhaSplitter() {
|
ShiroRekhaSplitter::ShiroRekhaSplitter() :
|
||||||
orig_pix_ = nullptr;
|
orig_pix_(nullptr),
|
||||||
segmentation_block_list_ = nullptr;
|
splitted_image_(nullptr),
|
||||||
splitted_image_ = nullptr;
|
pageseg_split_strategy_(NO_SPLIT),
|
||||||
global_xheight_ = kUnspecifiedXheight;
|
ocr_split_strategy_(NO_SPLIT),
|
||||||
perform_close_ = false;
|
debug_image_(nullptr),
|
||||||
debug_image_ = nullptr;
|
segmentation_block_list_(nullptr),
|
||||||
pageseg_split_strategy_ = NO_SPLIT;
|
global_xheight_(kUnspecifiedXheight),
|
||||||
ocr_split_strategy_ = NO_SPLIT;
|
perform_close_(false)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ShiroRekhaSplitter::~ShiroRekhaSplitter() {
|
ShiroRekhaSplitter::~ShiroRekhaSplitter() {
|
||||||
|
@ -67,8 +67,8 @@ TabFind::TabFind(int gridsize, const ICOORD &bleft, const ICOORD &tright, TabVec
|
|||||||
: AlignedBlob(gridsize, bleft, tright)
|
: AlignedBlob(gridsize, bleft, tright)
|
||||||
, resolution_(resolution)
|
, resolution_(resolution)
|
||||||
, image_origin_(0, tright.y() - 1)
|
, image_origin_(0, tright.y() - 1)
|
||||||
, v_it_(&vectors_) {
|
, v_it_(&vectors_)
|
||||||
width_cb_ = nullptr;
|
, width_cb_(nullptr) {
|
||||||
v_it_.add_list_after(vlines);
|
v_it_.add_list_after(vlines);
|
||||||
SetVerticalSkewAndParallelize(vertical_x, vertical_y);
|
SetVerticalSkewAndParallelize(vertical_x, vertical_y);
|
||||||
using namespace std::placeholders; // for _1
|
using namespace std::placeholders; // for _1
|
||||||
|
@ -99,10 +99,10 @@ Wordrec::Wordrec()
|
|||||||
"Save alternative paths found during chopping"
|
"Save alternative paths found during chopping"
|
||||||
" and segmentation search",
|
" and segmentation search",
|
||||||
params())
|
params())
|
||||||
, pass2_ok_split(0.0f) {
|
, language_model_(std::make_unique<LanguageModel>(&get_fontinfo_table(), &(getDict())))
|
||||||
prev_word_best_choice_ = nullptr;
|
, pass2_ok_split(0.0f)
|
||||||
language_model_ = std::make_unique<LanguageModel>(&get_fontinfo_table(), &(getDict()));
|
, prev_word_best_choice_(nullptr)
|
||||||
fill_lattice_ = nullptr;
|
, fill_lattice_(nullptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tesseract
|
} // namespace tesseract
|
||||||
|
@ -156,9 +156,9 @@ protected:
|
|||||||
return file::JoinPath(FLAGS_test_tmpdir, name);
|
return file::JoinPath(FLAGS_test_tmpdir, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
MasterTrainerTest() {
|
MasterTrainerTest() :
|
||||||
shape_table_ = nullptr;
|
shape_table_(nullptr),
|
||||||
master_trainer_ = nullptr;
|
master_trainer_(nullptr) {
|
||||||
}
|
}
|
||||||
~MasterTrainerTest() override {
|
~MasterTrainerTest() override {
|
||||||
delete shape_table_;
|
delete shape_table_;
|
||||||
|
Loading…
Reference in New Issue
Block a user