From be68c6d53d1d6a4e41ce169b4107f8ed39f85100 Mon Sep 17 00:00:00 2001 From: rachytski Date: Sat, 4 Feb 2012 16:16:29 +0400 Subject: [PATCH] don't use dynamic memory allocation when it's not necessary. --- yg/glyph_layout.cpp | 9 ++++++--- yg/glyph_layout.hpp | 14 ++++++-------- yg/path_text_element.cpp | 7 ++++++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/yg/glyph_layout.cpp b/yg/glyph_layout.cpp index 16e399c0d4..4459237d7a 100644 --- a/yg/glyph_layout.cpp +++ b/yg/glyph_layout.cpp @@ -69,6 +69,9 @@ namespace yg m_fontDesc(fontDesc), m_pivot(pt) { + m_entries.reserve(visText.size()); + m_metrics.reserve(visText.size()); + if (!m_fontDesc.IsValid()) return; @@ -381,17 +384,17 @@ namespace yg return m_lastVisible; } - vector const & GlyphLayout::entries() const + buffer_vector const & GlyphLayout::entries() const { return m_entries; } - vector const & GlyphLayout::metrics() const + buffer_vector const & GlyphLayout::metrics() const { return m_metrics; } - vector const & GlyphLayout::boundRects() const + buffer_vector const & GlyphLayout::boundRects() const { return m_boundRects; } diff --git a/yg/glyph_layout.hpp b/yg/glyph_layout.hpp index 0363225e3a..23bcc26179 100644 --- a/yg/glyph_layout.hpp +++ b/yg/glyph_layout.hpp @@ -45,10 +45,9 @@ namespace yg yg::FontDesc m_fontDesc; - vector m_metrics; - vector m_entries; - - vector m_boundRects; + buffer_vector m_metrics; + buffer_vector m_entries; + buffer_vector m_boundRects; m2::PointD m_pivot; @@ -83,10 +82,9 @@ namespace yg size_t firstVisible() const; size_t lastVisible() const; - vector const & entries() const; - vector const & metrics() const; - - vector const & boundRects() const; + buffer_vector const & entries() const; + buffer_vector const & metrics() const; + buffer_vector const & boundRects() const; m2::PointD const & pivot() const; yg::FontDesc const & fontDesc() const; diff --git a/yg/path_text_element.cpp b/yg/path_text_element.cpp index 2aac53f6ff..1a26e7721c 100644 --- a/yg/path_text_element.cpp +++ b/yg/path_text_element.cpp @@ -31,7 +31,12 @@ namespace yg { if (isDirtyRect()) { - m_boundRects = m_glyphLayout.boundRects(); + m_boundRects.clear(); + m_boundRects.reserve(m_glyphLayout.boundRects().size()); + + for (unsigned i = 0; i < m_glyphLayout.boundRects().size(); ++i) + m_boundRects.push_back(m_glyphLayout.boundRects()[i]); + // for (unsigned i = 0; i < m_boundRects.size(); ++i) // m_boundRects[i] = m2::Inflate(m_boundRects[i], m2::PointD(10, 10)); // m_boundRects[i].m2::Inflate(m2::PointD(40, 2)); //< to create more sparse street names structure