On Wed, Jun 29, 2005 at 01:53:35PM +0200, Murray Cumming wrote:
Using Glib::ustring has disadvantage that its operator[] runs in linear time in its argument, rather than constant time as one might expect. Similarly, I believe even its length() method takes linear time.
That's a problem with utf8, not ustring. GString doesn't offer any linear way to iterate through utf8 characters in linear time either.
Just to clarify: the main issue is that programmers don't expect operator[] to run in time proportional to its argument. What is operator[] useful for? When would one ever want to know what the 25th gunichar of a string is? For C++, iterators are the more appropriate access method. What data structures in the C++ standard library provide operator[] that run in time proportional to its argument? Cf std::list documentation in gnu libstdc++-6-4.0:
# Unlike std::vector and std::deque, random-access iterators are not # provided, so subscripting ( [] ) access is not allowed.
or the footnote in the [last publicly-visible draft of the] C++ standard:
# ... the operator[] and at member functions ...[2] # # [2:] These member functions are only provided by containers whose # iterators are random access iterators.
Thus, either operator[] should have been omitted from Glib::ustring, or it should index into bytes rather than gunichar's, or Glib::ustring should have chosen a representation that allows random access.
Feel free to submit a patch,
Yes, you're right, inkscape-devel isn't the right place for this; please excuse the rant.
pjrm.