summaryrefslogtreecommitdiffstats
path: root/src/lib/netlist/plib/pstring.cpp
diff options
context:
space:
mode:
author Couriersud <couriersud@gmx.org>2020-09-05 19:43:54 +0200
committer Couriersud <couriersud@gmx.org>2020-09-05 21:31:49 +0200
commitf3eb6324652fea263972087146fbdde9e32f9a0f (patch)
treef63d352948c3a4fcf62857839cc5c5359804b0f5 /src/lib/netlist/plib/pstring.cpp
parent4dd7e21f565b12e8487b884089d769f0b30147c6 (diff)
netlist: code maintenance and performance optimizations.
* rename some misleading type names * remove callback_t and replace by better scalable approach * hide implementations details * move sources classes from putil.h to psources.h * reduce code complexity * improve parsing performance, parsing netlists now is twice as fast. * fix issues around multi-byte string support * moved psplit into pstrutil.h
Diffstat (limited to 'src/lib/netlist/plib/pstring.cpp')
-rw-r--r--src/lib/netlist/plib/pstring.cpp70
1 files changed, 50 insertions, 20 deletions
diff --git a/src/lib/netlist/plib/pstring.cpp b/src/lib/netlist/plib/pstring.cpp
index b0dc3d313c6..f25b669c8ad 100644
--- a/src/lib/netlist/plib/pstring.cpp
+++ b/src/lib/netlist/plib/pstring.cpp
@@ -11,48 +11,73 @@
template<typename F>
int pstring_t<F>::compare(const pstring_t &right) const noexcept
{
- if (mem_t_size() == 0 && right.mem_t_size() == 0)
- return 0;
- if (right.mem_t_size() == 0)
- return 1;
- if (mem_t_size() == 0)
- return -1;
-
+#if 0
+ return m_str.compare(right.m_str);
+#else
auto si = this->begin();
auto ri = right.begin();
- while (si != this->end() && ri != right.end() && *si == *ri)
+ const auto se = this->end();
+ const auto re = right.end();
+
+ while (si != se && ri != re && *si == *ri)
{
++ri;
++si;
}
- if (si != this->end() && ri != right.end())
+ if (si != se && ri != re)
return plib::narrow_cast<int>(*si) - plib::narrow_cast<int>(*ri);
- if (this->mem_t_size() > right.mem_t_size())
+ if (si != se)
return 1;
- if (this->mem_t_size() < right.mem_t_size())
+ if (ri != re)
return -1;
return 0;
+#endif
}
template<typename F>
pstring_t<F> pstring_t<F>::substr(size_type start, size_type nlen) const
{
pstring_t ret;
+ auto ps = begin();
+ while (ps != end() && start > 0)
+ {
+ ++ps;
+ --start;
+ }
//FIXME: throw ?
- const size_type l = length();
- if (start < l)
+ if (ps != end())
{
- if (nlen == npos || start + nlen > l)
- nlen = l - start;
- auto ps = std::next(begin(), plib::narrow_cast<difference_type>(start));
- auto pe = std::next(ps, plib::narrow_cast<difference_type>(nlen));
+ auto pe = ps;
+ while (pe != end() && nlen > 0)
+ {
+ ++pe;
+ --nlen;
+ }
ret.m_str.assign(ps.p, pe.p);
}
return ret;
}
template<typename F>
+pstring_t<F> pstring_t<F>::substr(size_type start) const
+{
+ pstring_t ret;
+ auto ps = begin();
+ while (ps != end() && start > 0)
+ {
+ ++ps;
+ --start;
+ }
+ //FIXME: throw ?
+ if (ps != end())
+ {
+ ret.m_str.assign(ps.p, end().p);
+ }
+ return ret;
+}
+
+template<typename F>
typename pstring_t<F>::size_type pstring_t<F>::find(const pstring_t &search, size_type start) const noexcept
{
auto istart = std::next(begin(), static_cast<difference_type>(start));
@@ -75,9 +100,14 @@ typename pstring_t<F>::size_type pstring_t<F>::find(const pstring_t &search, siz
template<typename F>
typename pstring_t<F>::size_type pstring_t<F>::find(code_t search, size_type start) const noexcept
{
- pstring_t ss;
- traits_type::encode(search, ss.m_str);
- return find(ss, start);
+ auto i = std::next(begin(), static_cast<difference_type>(start));
+ for (; i != end(); ++i)
+ {
+ if (*i == search)
+ return start;
+ ++start;
+ }
+ return npos;
}
// ----------------------------------------------------------------------------------------