【发布时间】:2012-01-29 11:56:56
【问题描述】:
在 iOS 项目中使用 zlib 1.25 时,我在我的分析器(Instruments)中注意到函数 zError 被重复调用,并且占用了总膨胀时间的 50%。
有谁知道为什么 zError 会被这样调用?我没有在我自己的代码中的任何地方调用它,这是一个非常样板的膨胀函数,粘贴在下面:
int UPNExtractorGZInflate(const void *src, int srcLen, void *dst, int dstLen) {
z_stream strm = {0};
strm.total_in = strm.avail_in = srcLen;
strm.total_out = strm.avail_out = dstLen;
strm.next_in = (Bytef *) src;
strm.next_out = (Bytef *) dst;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
int err = -1;
int ret = -1;
err = inflateInit2(&strm, (15 + 16)); //15 window bits, and the +16 tells zlib to decode gzip
if (err == Z_OK) {
err = inflate(&strm, Z_FINISH);
if (err == Z_STREAM_END) {
ret = strm.total_out;
}
else {
inflateEnd(&strm);
return err;
}
}
else {
inflateEnd(&strm);
return err;
}
inflateEnd(&strm);
return ret;
}
这是相关的分析器输出(注意 zError 占用了总膨胀时间的 50%):
【问题讨论】:
标签: ios performance instruments zlib