Reputation: 291
strlen
complexity is O(1), because string structure save string length, but what about mb_strlen
? And please explain me, why?
Upvotes: 0
Views: 221
Reputation: 1191
Looking at source code in worst case it is O(N).
mbtab = encoding->mblen_table;
n = 0;
p = string->val;
k = string->len;
/* count */
if (p != NULL) {
while (n < k) {
m = mbtab[*p];
n += m;
p += m;
len++;
};
}
Upvotes: 1