找到《Learn iPhone and iPad Cocos2D Game Development》一书翻译中的一处错误

《Learn iPhone and iPad Cocos2D Game Development》一书有一段关于CCArray的描述:

CCArray通过将数组中的最后一个对象(nil)赋值给删除的位置,实现了fastRemoveObject和fastRemoveObjectAtIndex两个方法。避免了复制部份数组的内存。这让删除数组中的元素变的更快,不过这也意味着CCArray中的对象会改变位置。

cocos2d中fastRemoveObject和fastRemoveObjectAtIndex这两个方法最终都是通过下面这个函数来实现的


/** Removes object at specified index and fills the gap with the last object,
 thereby avoiding the need to push back subsequent objects.
 Behaviour undefined if index outside [0, num-1]. */
static inline void ccArrayFastRemoveObjectAtIndex(ccArray *arr, NSUInteger index)
{
	[arr->arr[index] release];
	NSUInteger last = --arr->num;
	arr->arr[index] = arr->arr[last];
}

很明显,最后一个对象并不是nil。翻译者画蛇添足,会造成一些读者理解上的困扰!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值