Replace resize(0) by clear() for std::vector

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2021-01-12 19:24:54 +01:00
parent 5104af6a15
commit 9b15e65900
12 changed files with 22 additions and 22 deletions

View File

@ -257,7 +257,7 @@ void ResultIterator::CalculateTextlineOrder(
std::vector<StrongScriptDirection> dirs;
std::vector<StrongScriptDirection>* directions;
directions = (dirs_arg != nullptr) ? dirs_arg : &dirs;
directions->resize(0);
directions->clear();
// A LTRResultIterator goes strictly left-to-right word order.
LTRResultIterator ltr_it(resit);
@ -268,7 +268,7 @@ void ResultIterator::CalculateTextlineOrder(
directions->push_back(ltr_it.WordDirection());
} while (ltr_it.Next(RIL_WORD) && !ltr_it.IsAtBeginningOf(RIL_TEXTLINE));
word_indices->resize(0);
word_indices->clear();
CalculateTextlineOrder(paragraph_is_ltr, *directions, word_indices);
}
@ -276,7 +276,7 @@ void ResultIterator::CalculateTextlineOrder(
bool paragraph_is_ltr,
const std::vector<StrongScriptDirection>& word_dirs,
std::vector<int>* reading_order) {
reading_order->resize(0);
reading_order->clear();
if (word_dirs.size() == 0)
return;

View File

@ -212,7 +212,7 @@ void TFile::OpenWrite(std::vector<char>* data) {
}
is_writing_ = true;
swap_ = false;
data_->resize(0);
data_->clear();
}
bool TFile::CloseWrite(const char* filename, FileWriter writer) {

View File

@ -244,7 +244,7 @@ bool UNICHARSET::encode_string(const char* str, bool give_up_on_failure,
std::vector<UNICHAR_ID> working_encoding;
std::vector<char> working_lengths;
std::vector<char> best_lengths;
encoding->resize(0); // Just in case str is empty.
encoding->clear(); // Just in case str is empty.
int str_length = strlen(str);
int str_pos = 0;
bool perfect = true;
@ -352,13 +352,13 @@ STRING UNICHARSET::debug_str(UNICHAR_ID id) const {
// Sets the normed_ids vector from the normed string. normed_ids is not
// stored in the file, and needs to be set when the UNICHARSET is loaded.
void UNICHARSET::set_normed_ids(UNICHAR_ID unichar_id) {
unichars[unichar_id].properties.normed_ids.resize(0);
unichars[unichar_id].properties.normed_ids.clear();
if (unichar_id == UNICHAR_SPACE && id_to_unichar(unichar_id)[0] == ' ') {
unichars[unichar_id].properties.normed_ids.push_back(UNICHAR_SPACE);
} else if (!encode_string(unichars[unichar_id].properties.normed.c_str(),
true, &unichars[unichar_id].properties.normed_ids,
nullptr, nullptr)) {
unichars[unichar_id].properties.normed_ids.resize(0);
unichars[unichar_id].properties.normed_ids.clear();
unichars[unichar_id].properties.normed_ids.push_back(unichar_id);
}
}

View File

@ -467,7 +467,7 @@ class TESS_API UNICHARSET {
// Record normalized version of unichar with the given unichar_id.
void set_normed(UNICHAR_ID unichar_id, const char* normed) {
unichars[unichar_id].properties.normed = normed;
unichars[unichar_id].properties.normed_ids.resize(0);
unichars[unichar_id].properties.normed_ids.clear();
}
// Sets the normed_ids vector from the normed string. normed_ids is not
// stored in the file, and needs to be set when the UNICHARSET is loaded.

View File

@ -1182,7 +1182,7 @@ void Classify::ExpandShapesAndApplyCorrections(
if (r == mapped_results.size()) {
mapped_results.push_back(*int_result);
mapped_results[r].unichar_id = unichar_id;
mapped_results[r].fonts.resize(0);
mapped_results[r].fonts.clear();
}
for (int i = 0; i < shape[c].font_ids.size(); ++i) {
mapped_results[r].fonts.push_back(

View File

@ -1190,7 +1190,7 @@ int IntegerMatcher::FindBestMatch(
UnicharRating* result) {
int best_match = 0;
result->config = 0;
result->fonts.resize(0);
result->fonts.clear();
result->fonts.reserve(class_template->NumConfigs);
/* Find best match */

View File

@ -41,7 +41,7 @@ namespace tesseract {
int ShapeClassifier::UnicharClassifySample(
const TrainingSample& sample, Pix* page_pix, int debug,
UNICHAR_ID keep_this, std::vector<UnicharRating>* results) {
results->resize(0);
results->clear();
std::vector<ShapeRating> shape_results;
int num_shape_results = ClassifySample(sample, page_pix, debug, keep_this,
&shape_results);

View File

@ -488,8 +488,8 @@ void LSTMRecognizer::LabelsViaReEncode(const NetworkIO& output,
void LSTMRecognizer::LabelsViaSimpleText(const NetworkIO& output,
std::vector<int>* labels,
std::vector<int>* xcoords) {
labels->resize(0);
xcoords->resize(0);
labels->clear();
xcoords->clear();
const int width = output.Width();
for (int t = 0; t < width; ++t) {
float score = 0.0f;

View File

@ -192,8 +192,8 @@ void RecodeBeamSearch::calculateCharBoundaries(std::vector<int>* starts,
// Returns the best path as labels/scores/xcoords similar to simple CTC.
void RecodeBeamSearch::ExtractBestPathAsLabels(
std::vector<int>* labels, std::vector<int>* xcoords) const {
labels->resize(0);
xcoords->resize(0);
labels->clear();
xcoords->clear();
GenericVector<const RecodeNode*> best_nodes;
ExtractBestPaths(&best_nodes, nullptr);
// Now just run CTC on the best nodes.
@ -547,10 +547,10 @@ void RecodeBeamSearch::ExtractPathAsUnicharIds(
std::vector<int>* unichar_ids, std::vector<float>* certs,
std::vector<float>* ratings, std::vector<int>* xcoords,
std::vector<int>* character_boundaries) {
unichar_ids->resize(0);
certs->resize(0);
ratings->resize(0);
xcoords->resize(0);
unichar_ids->clear();
certs->clear();
ratings->clear();
xcoords->clear();
std::vector<int> starts;
std::vector<int> ends;
// Backtrack extracting only valid, non-duplicate unichar-ids.

View File

@ -270,7 +270,7 @@ int PangoFontInfo::DropUncoveredChars(std::string* utf8_text) const {
if (font == nullptr) {
// Font not found, drop all characters.
num_dropped_chars = utf8_text->length();
utf8_text->resize(0);
utf8_text->clear();
return num_dropped_chars;
}
PangoCoverage* coverage = pango_font_get_coverage(font, nullptr);

View File

@ -694,7 +694,7 @@ bool LSTMTrainer::EncodeString(const STRING& str, const UNICHARSET& unicharset,
}
int err_index;
std::vector<int> internal_labels;
labels->resize(0);
labels->clear();
if (!simple_text) labels->push_back(null_char);
std::string cleaned = unicharset.CleanupString(str.c_str());
if (unicharset.encode_string(cleaned.c_str(), true, &internal_labels, nullptr,

View File

@ -74,7 +74,7 @@ static int Main(int argc, char** argv) {
tprintf("Extracting unicharset from box file %s\n", argv[arg]);
} else {
tprintf("Extracting unicharset from plain text file %s\n", argv[arg]);
texts.resize(0);
texts.clear();
file_data.split('\n', &texts);
}
AddStringsToUnicharset(texts, FLAGS_norm_mode, &unicharset);