+ /* A call to strxfrm costs about 20 times more than a call to
+ strdup of the result. Therefore it is worth to try to avoid
+ calling strxfrm more than once on a given string, by making
+ enough room before calling strxfrm.
+ The size of the strxfrm result, k, is likely to be between
+ l and 3 * l. */
+ if (3 * l >= allocated - length)
+ {
+ /* Grow the result buffer. */
+ size_t new_allocated;
+ char *new_result;
+
+ new_allocated = length + 3 * l + 1;
+ if (new_allocated < 2 * allocated)
+ new_allocated = 2 * allocated;
+ if (new_allocated < 64)
+ new_allocated = 64;
+ if (result == resultbuf)
+ new_result = (char *) malloc (new_allocated);
+ else
+ new_result = (char *) realloc (result, new_allocated);
+ if (new_result != NULL)
+ {
+ allocated = new_allocated;
+ result = new_result;
+ }
+ }
+