← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 743.d.6.k · 生成模型:未记录

迭代器的零成本抽象

理解等级:高级

迭代器隐藏控制逻辑,不必为这种表达层额外付出运行开销。书中的搜索实验仅比较一个文本和一个查询,无法据此断定适配器总更快。音频示例中编译器得知迭代固定为 12 项,可通过展开消除内层循环控制,并在确定索引安全时省略运行时边界检查。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第13章 函数式语言特性:迭代器与闭包(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c13.xhtml`,块 0203) - 结论依据:原文用基准局限与编译到低层的观点界定抽象成本。 - 原始内容:For a more comprehensive benchmark, you should check using various texts of various sizes as the contents, different words and words of different lengths as the query, and all kinds of other variations. The point is this: iterators, although a high-level abstraction, get compiled down to roughly the same code as if you’d written the lower-level code yourself.