[[RESEND: I don't think anyone committed this patch, and I didn't
want it to fall between the cracks. Tx -- wjc]]
This patch, against 071200 nightly sources, provides a minor
performance improvement for the Unix version of drawChars(). It
eliminates the overhead of new/delete for most invocations of the
function.
For every Unix drawChars(), a copy of the string has to be made to
convert from 16bit to 32bit character elements. Before this patch,
that was always done via new/delete of enough storage to hold the
copy. This patch uses a blob of automatic storage for the copy if the
size of the string is less than 150 characters (which should cover all
the normal cases and a fair percentage of the abnormal ones), else it
reverts to the old new/delete stuff.
The BeOS drawChars() has the same characteristics as the Unix version,
but I had high confidence I would break the BeOS build if I tried to
code that up without being able to compile it.
--
[EMAIL PROTECTED] (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/af/gr/unix/gr_UnixGraphics.cpp
abi-071200/src/af/gr/unix/gr_UnixGraphics.cpp
--- abi-071200-ORIG/src/af/gr/unix/gr_UnixGraphics.cpp Sun Jul 9 13:54:11 2000
+++ abi-071200/src/af/gr/unix/gr_UnixGraphics.cpp Wed Jul 12 22:50:11 2000
@@ -112,42 +112,26 @@
UT_ASSERT(m_pFont);
GdkFont *font = m_pFont->getGdkFont();
-
- if (iLength > 1) {
- /*
- * TODO - We need to seriously look for a way to avoid this.
- * Doing a memory allocation on every draw is painful.
- */
- // Blargh... GDK wants strings in 32 bits, we use 16 internally
- GdkWChar *pNChars = new GdkWChar[iLength];
-
- for (int i = 0; i < iLength; i++)
- {
- pNChars[i] = remapGlyph(pChars[i + iCharOffset], UT_FALSE);
- }
-
-
- // Use "wide-char" function
- gdk_draw_text_wc (m_pWin, font, m_pGC,
- xoff, yoff + font->ascent, pNChars, iLength);
- //XDrawString16 (drawable_private->xdisplay, drawable_private->xwindow,
- // gc_private->xgc, xoff, yoff +
xfont->ascent, pNChars,
- // iLength);
-
- delete pNChars;
- } else {
-
- // the vast majority of calls to this function are
- // to draw a single character, so we'll optimize this case
-
- GdkWChar pChar = remapGlyph(pChars[iCharOffset], UT_FALSE);
- gdk_draw_text_wc (m_pWin, font, m_pGC,
- xoff, yoff + font->ascent, &pChar, 1);
+ // Blargh... GDK wants strings in 32 bits, we use 16 internally
+ GdkWChar *pNChars, utb[150]; // arbitrary biggish size for utb
+ if ((unsigned)iLength < (sizeof(utb) / sizeof(utb[0])))
+ {
+ // avoid new/delete overhead for most cases via ubiquitous temp buf
+ pNChars = utb;
+ }
+ else
+ {
+ pNChars = new GdkWChar[iLength];
+ }
+ for (int i = 0; i < iLength; i++)
+ {
+ pNChars[i] = remapGlyph(pChars[i + iCharOffset], UT_FALSE);
}
+ // Use "wide-char" function
+ gdk_draw_text_wc(m_pWin, font, m_pGC, xoff, yoff + font->ascent, pNChars,
+iLength);
+ if (pNChars != utb) delete pNChars;
-#if 1
flush();
-#endif
}
void GR_UnixGraphics::setFont(GR_Font * pFont)