[英]Which complexity mb_strlen?
strlen
complexity is O(1), because string structure save string length, but what about mb_strlen
? strlen
复杂度为O(1),因为字符串结构节省了字符串长度,但是mb_strlen
呢? And please explain me, why? 并请解释一下为什么?
Looking at source code in worst case it is O(N). 在最坏的情况下查看源代码是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++;
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.