Skip to content

Commit

Permalink
Fixed excessive stack use
Browse files Browse the repository at this point in the history
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@241 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
theraysmith committed Jun 2, 2009
1 parent af1a2dd commit 2186613
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
34 changes: 17 additions & 17 deletions classify/adaptmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ LIST AdaptiveClassifier(TBLOB *Blob, TBLOB *DotBlob, TEXTROW *Row) {
** History: Mon Mar 11 10:00:58 1991, DSJ, Created.
*/
LIST Choices;
ADAPT_RESULTS Results;
ADAPT_RESULTS* Results = new ADAPT_RESULTS;
LINE_STATS LineStats;

if (FailedAdaptionsBeforeReset >= 0 &&
Expand All @@ -408,35 +408,35 @@ LIST AdaptiveClassifier(TBLOB *Blob, TBLOB *DotBlob, TEXTROW *Row) {
AdaptedTemplates = NewAdaptedTemplates ();
EnterClassifyMode;

Results.BlobLength = MAX_INT32;
Results.NumMatches = 0;
Results.BestRating = WORST_POSSIBLE_RATING;
Results.BestClass = NO_CLASS;
Results.BestConfig = 0;
Results->BlobLength = MAX_INT32;
Results->NumMatches = 0;
Results->BestRating = WORST_POSSIBLE_RATING;
Results->BestClass = NO_CLASS;
Results->BestConfig = 0;
GetLineStatsFromRow(Row, &LineStats);
InitMatcherRatings (Results.Ratings);
InitMatcherRatings (Results->Ratings);

DoAdaptiveMatch(Blob, &LineStats, &Results);
RemoveBadMatches(&Results);
DoAdaptiveMatch(Blob, &LineStats, Results);
RemoveBadMatches(Results);

/* save ratings in a global so that CompareCurrentRatings() can see them */
CurrentRatings = Results.Ratings;
qsort ((void *) (Results.Classes), Results.NumMatches,
CurrentRatings = Results->Ratings;
qsort((void*) (Results->Classes), Results->NumMatches,
sizeof (CLASS_ID), CompareCurrentRatings);
RemoveExtraPuncs(&Results);
Choices = ConvertMatchesToChoices (&Results);
RemoveExtraPuncs(Results);
Choices = ConvertMatchesToChoices(Results);

if (MatcherDebugLevel >= 1) {
cprintf ("AD Matches = ");
PrintAdaptiveMatchResults(stdout, &Results);
PrintAdaptiveMatchResults(stdout, Results);
}

if (LargeSpeckle (Blob, Row))
Choices = AddLargeSpeckleTo (Choices);

#ifndef GRAPHICS_DISABLED
if (EnableAdaptiveDebugger)
DebugAdaptiveClassifier(Blob, &LineStats, &Results);
DebugAdaptiveClassifier(Blob, &LineStats, Results);
#endif

NumClassesOutput += count (Choices);
Expand All @@ -447,8 +447,8 @@ LIST AdaptiveClassifier(TBLOB *Blob, TBLOB *DotBlob, TEXTROW *Row) {
return (append_choice (NIL, "", empty_lengths, 50.0f, -20.0f, -1));
}

return (Choices);

delete Results;
return Choices;
} /* AdaptiveClassifier */


Expand Down
15 changes: 3 additions & 12 deletions textord/scanedg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,8 @@ DLLSYM void block_edges( //get edges in a block
BLOCK_LINE_IT line_it = block; //line iterator
IMAGELINE bwline; //thresholded line
//lines in progress
CRACKEDGE *ptrlinemem[MAXIMAGEWIDTH];
CRACKEDGE **ptrline = ptrlinemem;

if (t_image->get_xsize()+1 > MAXIMAGEWIDTH) {
ptrline = new CRACKEDGE*[t_image->get_xsize()+1];
}

//block box
block->bounding_box (bleft, tright);
CRACKEDGE **ptrline = new CRACKEDGE*[t_image->get_xsize()+1];
block->bounding_box (bleft, tright); // block box
block_bleft = bleft;
block_tright = tright;
for (x = tright.x () - bleft.x (); x >= 0; x--)
Expand Down Expand Up @@ -93,9 +86,7 @@ DLLSYM void block_edges( //get edges in a block

free_crackedges(free_cracks); //really free them
free_cracks = NULL;
if (ptrline != ptrlinemem) {
delete [] ptrline;
}
delete[] ptrline;
}


Expand Down

0 comments on commit 2186613

Please sign in to comment.