ibireme / YYCache

High performance cache framework for iOS.
MIT License
2.38k stars 515 forks source link

removeNode:(_YYLinkedMapNode *)node 头尾节点处理 #143

Closed info3781 closed 5 years ago

info3781 commented 5 years ago
- (void)removeNode:(_YYLinkedMapNode *)node {
    CFDictionaryRemoveValue(_dic, (__bridge const void *)(node->_key));
    _totalCost -= node->_cost;
    _totalCount--;
    if (node->_next) node->_next->_prev = node->_prev;
    if (node->_prev) node->_prev->_next = node->_next;
    if (_head == node) _head = node->_next;
    if (_tail == node) _tail = node->_prev;
}

删除某个节点的时候,当删除的节点是头尾节点的时候,处理感觉有点问题。

if (_head == node) {
    _head = node->_next;
    _head->_prev = nil; //need reset
}
if (_tail == node) {
    _tail = node->_prev;
    _tail->_next = nil; //need reset
}
info3781 commented 5 years ago

上面的分支其实已经处理了该情况。