g_strchug, g_strchomp, g_strstrip



Hello all!

This may seem insignificant to some. But my projects usually involve
many thousands of operations on potentially very long strings. All the
little things start to add up.

On a whim, I looked at the #define for g_strstrip:

  /* removes leading & trailing spaces */
  #define g_strstrip( string )	g_strchomp (g_strchug (string))

Letting alone that I might prefer to make a proper function for this to
avoid calling strlen() twice, isn't this definition backwards
efficiency-wise? I mean that, if g_strchug() could call memmove(),
wouldn't you want to do that *after* shortening the string with
g_strchomp()?

Also, g_strchug() unconditionally does:

  g_memmove (string, start, strlen ((gchar *) start) + 1);

This should be wrapped in "if (string != start)" to avoid calling
strlen() in the (rather common) case of not moving any bytes at all.

I don't see any reason at all for not making these two changes.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]