patch: remove misc memory allocation/free penalties


Subject: patch: remove misc memory allocation/free penalties
From: WJCarpenter (bill-abisource@carpenter.ORG)
Date: Thu Jul 13 2000 - 02:51:50 CDT


This patch, against 071200 nightly sources, removes a few instances of
memory allocations and frees that don't have to happen. Code is XP,
tested on Linux.

1. In fp_TextRun::_drawSquiggle(), automatic storage is now used if
the number of points in the squiggle is less than 100, which covers
most cases. This routine is called on the way to drawing squiggles
under misspelled words.

2. In fp_TabRun::_drawArrow(), a polyline with 8 points is used to
draw an arrow for invisible tab characters. The function now uses an
automatic storage array of 8 points.

I just happened to stumble across these as I was poking around looking
for something else.

-- 
bill@carpenter.ORG (WJCarpenter)    PGP 0x91865119
38 95 1B 69 C9 C6 3D 25    73 46 32 04 69 D6 ED F3

diff -ru abi-071200-ORIG/src/text/fmt/xp/fp_Run.cpp abi-071200/src/text/fmt/xp/fp_Run.cpp --- abi-071200-ORIG/src/text/fmt/xp/fp_Run.cpp Sun Jul 9 16:28:29 2000 +++ abi-071200/src/text/fmt/xp/fp_Run.cpp Thu Jul 13 00:39:25 2000 @@ -464,8 +464,7 @@ #define NPOINTS 8 - UT_Point * points = (UT_Point *)calloc(NPOINTS,sizeof(UT_Point)); - UT_ASSERT(points); + UT_Point * points[NPOINTS]; UT_sint32 cur_linewidth = 1 + (UT_MAX(10,m_iAscent) - 10) / 8; UT_uint32 iyAxis = iTop + m_pLine->getAscent() * 2 / 3; @@ -498,7 +497,6 @@ m_pG->setColor(m_colorFG); m_pG->polyLine(points,NPOINTS); - FREEP(points); } void fp_TabRun::_draw(dg_DrawArgs* pDA) diff -ru abi-071200-ORIG/src/text/fmt/xp/fp_TextRun.cpp abi-071200/src/text/fmt/xp/fp_TextRun.cpp --- abi-071200-ORIG/src/text/fmt/xp/fp_TextRun.cpp Thu Jul 6 16:42:02 2000 +++ abi-071200/src/text/fmt/xp/fp_TextRun.cpp Thu Jul 13 00:36:17 2000 @@ -1195,7 +1195,15 @@ to move the coordinates into a platform-specific point structure. They're all x, y but different widths. Bummer. */ - UT_Point * points = (UT_Point *)calloc(nPoints, sizeof(UT_Point)); + UT_Point * points, scratchpoints[100]; + if ((unsigned)nPoints < (sizeof(scratchpoints)/sizeof(scratchpoints[0]))) + { + points = scratchpoints; + } + else + { + points = new UT_Point[nPoints]; + } UT_ASSERT(points); points[0].x = left; @@ -1217,7 +1225,7 @@ m_pG->polyLine(points, nPoints); - FREEP(points); + if (points != scratchpoints) delete points; } void fp_TextRun::drawSquiggle(UT_uint32 iOffset, UT_uint32 iLen)



This archive was generated by hypermail 2b25 : Thu Jul 13 2000 - 11:30:27 CDT