mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-21 17:13:09 +08:00
Optimize length method for ELIST, ELIST2
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
4104876b08
commit
3705989c94
@ -76,22 +76,6 @@ void ELIST::assign_to_sublist( // to this list
|
||||
last = start_it->extract_sublist(end_it);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* ELIST::length
|
||||
*
|
||||
* Return count of elements on list
|
||||
**********************************************************************/
|
||||
|
||||
int32_t ELIST::length() const { // count elements
|
||||
ELIST_ITERATOR it(const_cast<ELIST *>(this));
|
||||
int32_t count = 0;
|
||||
|
||||
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* ELIST::sort
|
||||
*
|
||||
|
@ -147,7 +147,17 @@ public:
|
||||
ELIST_ITERATOR *start_it, // from list start
|
||||
ELIST_ITERATOR *end_it); // from list end
|
||||
|
||||
int32_t length() const; // # elements in list
|
||||
// # elements in list
|
||||
int32_t length() const {
|
||||
int32_t count = 0;
|
||||
if (last != nullptr) {
|
||||
count = 1;
|
||||
for (auto it = last->next; it != last; it = it->next) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void sort( // sort elements
|
||||
int comparator( // comparison routine
|
||||
@ -273,7 +283,10 @@ public:
|
||||
void exchange( // positions of 2 links
|
||||
ELIST_ITERATOR *other_it); // other iterator
|
||||
|
||||
int32_t length() const; //# elements in list
|
||||
//# elements in list
|
||||
int32_t length() const {
|
||||
return list->length();
|
||||
}
|
||||
|
||||
void sort( // sort elements
|
||||
int comparator( // comparison routine
|
||||
@ -734,23 +747,6 @@ inline bool ELIST_ITERATOR::cycled_list() const {
|
||||
return ((list->empty()) || ((current == cycle_pt) && started_cycling));
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* ELIST_ITERATOR::length()
|
||||
*
|
||||
* Return the length of the list
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
inline int32_t ELIST_ITERATOR::length() const {
|
||||
#ifndef NDEBUG
|
||||
if (!list) {
|
||||
NO_LIST.error("ELIST_ITERATOR::length", ABORT, nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
return list->length();
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* ELIST_ITERATOR::sort()
|
||||
*
|
||||
|
@ -77,22 +77,6 @@ void ELIST2::assign_to_sublist( // to this list
|
||||
last = start_it->extract_sublist(end_it);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* ELIST2::length
|
||||
*
|
||||
* Return count of elements on list
|
||||
**********************************************************************/
|
||||
|
||||
int32_t ELIST2::length() const { // count elements
|
||||
ELIST2_ITERATOR it(const_cast<ELIST2 *>(this));
|
||||
int32_t count = 0;
|
||||
|
||||
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* ELIST2::sort
|
||||
*
|
||||
|
@ -123,7 +123,17 @@ public:
|
||||
ELIST2_ITERATOR *start_it, // from list start
|
||||
ELIST2_ITERATOR *end_it); // from list end
|
||||
|
||||
int32_t length() const; // # elements in list
|
||||
// # elements in list
|
||||
int32_t length() const {
|
||||
int32_t count = 0;
|
||||
if (last != nullptr) {
|
||||
count = 1;
|
||||
for (auto it = last->next; it != last; it = it->next) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void sort( // sort elements
|
||||
int comparator( // comparison routine
|
||||
@ -237,7 +247,10 @@ public:
|
||||
void exchange( // positions of 2 links
|
||||
ELIST2_ITERATOR *other_it); // other iterator
|
||||
|
||||
int32_t length() const; //# elements in list
|
||||
//# elements in list
|
||||
int32_t length() const {
|
||||
return list->length();
|
||||
}
|
||||
|
||||
void sort( // sort elements
|
||||
int comparator( // comparison routine
|
||||
@ -752,23 +765,6 @@ inline bool ELIST2_ITERATOR::cycled_list() const {
|
||||
return ((list->empty()) || ((current == cycle_pt) && started_cycling));
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* ELIST2_ITERATOR::length()
|
||||
*
|
||||
* Return the length of the list
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
inline int32_t ELIST2_ITERATOR::length() const {
|
||||
#ifndef NDEBUG
|
||||
if (!list) {
|
||||
NO_LIST.error("ELIST2_ITERATOR::length", ABORT, nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
return list->length();
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* ELIST2_ITERATOR::sort()
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user