Here a patch which avoids a virtual call and the the allocations when calling Painter::lines.
I've tested it with Qt4, but the changes are similar to the other frontends, and should make no problem. Here the current Painter::lines implementations: Qt4: see patch Qt3: void QLPainter::lines(int const * xp, int const * yp, int np, LColor_color col, line_style ls, line_width lw) { // FIXME ? // Must use new as np is not known at compile time. boost::scoped_array<QCOORD> points(new QCOORD[np * 2]); XForms: void XPainter::lines(int const * xp, int const * yp, int np, LColor_color col, line_style ls, line_width lw) { boost::scoped_array<XPoint> points(new XPoint[np]); Gtk: void GPainter::lines(int const * xp, int const * yp, int np, LColor_color col, line_style ls, line_width lw) { setForeground(col); setLineParam(ls, lw); std::vector<Gdk::Point> points(np); (aren't there also allocations?)
Index: frontends/Painter.h =================================================================== --- frontends/Painter.h (Revision 13994) +++ frontends/Painter.h (Arbeitskopie) @@ -98,6 +98,14 @@ line_style = line_solid, line_width = line_thin) = 0; + template<unsigned int np> + void lines( + int const * xp, + int const * yp, + LColor_color, + line_style = line_solid, + line_width = line_thin); + /// draw a rectangle virtual void rectangle( int x, int y, Index: frontends/qt4/QLPainter.h =================================================================== --- frontends/qt4/QLPainter.h (Revision 13994) +++ frontends/qt4/QLPainter.h (Arbeitskopie) @@ -147,6 +147,10 @@ /// the working area QWorkArea * qwa_; + + ///Painter is friend because the template + /// function lines needs access + friend class Painter; }; Index: insets/insetspecialchar.C =================================================================== --- insets/insetspecialchar.C (Revision 13994) +++ insets/insetspecialchar.C (Arbeitskopie) @@ -103,7 +103,7 @@ xp[2] = ox + w; yp[2] = y - h/2; xp[3] = ox; yp[3] = y; - pi.pain.lines(xp, yp, 4, LColor::special); + pi.pain.lines<4>(xp, yp, LColor::special); break; } } Index: insets/insetlatexaccent.C =================================================================== --- insets/insetlatexaccent.C (Revision 13994) +++ insets/insetlatexaccent.C (Arbeitskopie) @@ -465,7 +465,7 @@ xp[0] = int(x2 - hg35); yp[0] = int(y + hg35); xp[1] = int(x2); yp[1] = int(y + hg); xp[2] = int(x2 + hg35); yp[2] = int(y + hg35); - pi.pain.lines(xp, yp, 3, LColor::foreground); + pi.pain.lines<3>(xp, yp, LColor::foreground); break; } @@ -484,7 +484,7 @@ xp[2] = int(x + dim_.wid + (hg35 / 2.0)); yp[2] = y + int(hg); - pi.pain.lines(xp, yp, 3, LColor::foreground); + pi.pain.lines<3>(xp, yp, LColor::foreground); break; } @@ -518,7 +518,7 @@ xp[3] = x2 + hg / 4; yp[3] = y + int(hg); - pi.pain.lines(xp, yp, 4, LColor::foreground); + pi.pain.lines<4>(xp, yp, LColor::foreground); break; } @@ -532,7 +532,7 @@ xp[1] = int(x + dim_.wid * 0.75); yp[1] = y + int(hg); - pi.pain.lines(xp, yp, 2, LColor::foreground); + pi.pain.lines<2>(xp, yp, LColor::foreground); break; } Index: insets/insetspace.C =================================================================== --- insets/insetspace.C (Revision 13994) +++ insets/insetspace.C (Arbeitskopie) @@ -95,9 +95,9 @@ yp[3] = y - max(h / 4, 1); if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN) - pi.pain.lines(xp, yp, 4, LColor::latex); + pi.pain.lines<4>(xp, yp, LColor::latex); else - pi.pain.lines(xp, yp, 4, LColor::special); + pi.pain.lines<4>(xp, yp, LColor::special); } Index: insets/insetnewline.C =================================================================== --- insets/insetnewline.C (Revision 13994) +++ insets/insetnewline.C (Arbeitskopie) @@ -103,7 +103,7 @@ xp[2] = int(x + wid * 0.625); } - pi.pain.lines(xp, yp, 3, LColor::eolmarker); + pi.pain.lines<3>(xp, yp, LColor::eolmarker); yp[0] = int(y - 0.500 * asc * 0.75); yp[1] = int(y - 0.500 * asc * 0.75); @@ -119,7 +119,7 @@ xp[2] = int(x); } - pi.pain.lines(xp, yp, 3, LColor::eolmarker); + pi.pain.lines<3>(xp, yp, LColor::eolmarker); } Index: mathed/math_rootinset.C =================================================================== --- mathed/math_rootinset.C (Revision 13994) +++ mathed/math_rootinset.C (Arbeitskopie) @@ -63,7 +63,7 @@ xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2; //xp[4] = x; yp[4] = y + (d - a)/2 + 2; xp[4] = x + w - 5; yp[4] = y + (d - a)/2 + 4; - pi.pain.lines(xp, yp, 5, LColor::math); + pi.pain.lines<5>(xp, yp, LColor::math); drawMarkers(pi, x, y); } Index: mathed/math_spaceinset.C =================================================================== --- mathed/math_spaceinset.C (Revision 13994) +++ mathed/math_spaceinset.C (Arbeitskopie) @@ -106,7 +106,7 @@ xp[2] = x + w - 2; yp[2] = y; xp[3] = x + w - 2; yp[3] = y - 3; - pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math); + pi.pain.lines<4>(xp, yp, (space_ < 3) ? LColor::latex : LColor::math); } Index: mathed/math_sqrtinset.C =================================================================== --- mathed/math_sqrtinset.C (Revision 13994) +++ mathed/math_sqrtinset.C (Arbeitskopie) @@ -53,7 +53,7 @@ xp[1] = x + 8; yp[1] = y - a + 1; xp[2] = x + 5; yp[2] = y + d - 1; xp[3] = x; yp[3] = y + (d - a)/2; - pi.pain.lines(xp, yp, 4, LColor::math); + pi.pain.lines<4>(xp, yp, LColor::math); drawMarkers(pi, x, y); } Index: frontends/qt4/QLPainter.C =================================================================== --- frontends/qt4/QLPainter.C (Revision 13994) +++ frontends/qt4/QLPainter.C (Arbeitskopie) @@ -113,7 +113,39 @@ setQPainterPen(qp, col, ls, lw).drawPolyline(points.get(), np); } +template<unsigned int np> +void Painter::lines(int const * xp, int const * yp, + LColor_color col, + line_style ls, + line_width lw) +{ + // FIXME ? + // Must use new as np is not known at compile time. + //boost::scoped_array<QPoint> points(new QPoint[np]); + + QPoint points[np]; + + for (int i = 0; i < np; ++i) { + points[i].setX(xp[i]); + points[i].setY(yp[i]); + } + + QLPainter* actual_this(static_cast<QLPainter*>(this)); + QPainter qp(actual_this->qwa_->paintDevice()); + actual_this->setQPainterPen(qp, col, ls, lw).drawPolyline(points, np); +} + +// explicit instantiations. when you use values greater +// than 6 you must add a instantiation to avoid linker errors +template void Painter::lines<1>(int const*,int const*,LColor_color,line_style,line_width); +template void Painter::lines<2>(int const*,int const*,LColor_color,line_style,line_width); +template void Painter::lines<3>(int const*,int const*,LColor_color,line_style,line_width); +template void Painter::lines<4>(int const*,int const*,LColor_color,line_style,line_width); +template void Painter::lines<5>(int const*,int const*,LColor_color,line_style,line_width); +template void Painter::lines<6>(int const*,int const*,LColor_color,line_style,line_width); + + void QLPainter::rectangle(int x, int y, int w, int h, LColor_color col, line_style ls,