summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-07-27 21:36:32 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-07-27 21:36:32 +0100
commit14f59d415d2e77d70e9282ec100029b87cbb1799 (patch)
tree94c584dad65fbe412769ea3b53591b838f15321c /src
parentdf0773feeb59391c998f30c658b80997790f30fd (diff)
Avoid underlying iterator copies in utf8_iterator
Diffstat (limited to 'src')
-rw-r--r--src/utf8.hh19
-rw-r--r--src/utf8_iterator.hh4
2 files changed, 17 insertions, 6 deletions
diff --git a/src/utf8.hh b/src/utf8.hh
index 8e7d209a..62d9dcbd 100644
--- a/src/utf8.hh
+++ b/src/utf8.hh
@@ -25,13 +25,19 @@ inline bool is_character_start(char c)
return (c & 0xC0) != 0x80;
}
-// returns an iterator to next character first byte
template<typename Iterator>
-Iterator next(Iterator it, const Iterator& end)
+void to_next(Iterator& it, const Iterator& end)
{
if (it != end and read(it) & 0x80)
while (it != end and (*(it) & 0xC0) == 0x80)
++it;
+}
+
+// returns an iterator to next character first byte
+template<typename Iterator>
+Iterator next(Iterator it, const Iterator& end)
+{
+ to_next(it, end);
return it;
}
@@ -45,12 +51,17 @@ Iterator finish(Iterator it, const Iterator& end)
return it;
}
-// returns an iterator to the previous character first byte
template<typename Iterator>
-Iterator previous(Iterator it, const Iterator& begin)
+void to_previous(Iterator& it, const Iterator& begin)
{
while (it != begin and (*(--it) & 0xC0) == 0x80)
;
+}
+// returns an iterator to the previous character first byte
+template<typename Iterator>
+Iterator previous(Iterator it, const Iterator& begin)
+{
+ to_previous(it, begin);
return it;
}
diff --git a/src/utf8_iterator.hh b/src/utf8_iterator.hh
index 6e8f760b..c6589160 100644
--- a/src/utf8_iterator.hh
+++ b/src/utf8_iterator.hh
@@ -34,7 +34,7 @@ public:
iterator& operator++()
{
- m_it = utf8::next(m_it, m_end);
+ utf8::to_next(m_it, m_end);
invalidate_value();
return *this;
}
@@ -48,7 +48,7 @@ public:
iterator& operator--()
{
- m_it = utf8::previous(m_it, m_begin);
+ utf8::to_previous(m_it, m_begin);
invalidate_value();
return *this;
}