我一遍又一遍地看到这一点,为什么在循环中使用快速枚举而不是NSEnumerator使用它更快nextObject:.

所述ÿ轴表示平均访问时间(单位:ns),以在列表/阵列(总时间来访问由元素的数目除以所有元素)的每个节点.
的X轴代表被遍历数组中元素的数目.
其中red是一个实现,NSMutableArrayblue是我的链表(CHTape).
在每个外部循环中,每个列表/数组都@""附加一个空字符串.在内部循环中,检索每个列表/数组中的每个字符串,这是定时和记录的.在所有时间之后,我们在Wolfram语言输出中输出以生成情节.
如何NSMutableArray实现如此惊人和一致的结果?如何实现类似?
我的NSFastEnumeration实现:
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained [])stackBuffer count:(NSUInteger)len
{
if (state->state == 0)
{
state->state = 1;
state->mutationsPtr = &state->extra[1];
state->extra[0] = (unsigned long)head;
}
CHTapeNode *cursor = (__bridge CHTapeNode *)((void *)state->extra[0]);
NSUInteger i = 0;
while ( cursor != nil && i < len )
{
stackBuffer[i] = cursor->payload;
cursor = cursor->next;
i++;
}
state->extra[0] = (unsigned long)cursor;
state->itemsPtr = stackBuffer;
return …Run Code Online (Sandbox Code Playgroud)