휘샤's Blog
천천히 서둘러라

if-else vs instance

Tip 2009/12/01 11:43 by 휘샤


이클립스 내부 소스를 보니 이런 부분이 있다.

        switch (strategies.size()) {
        // optimization
        case 0:
            break;

        case 1:
            ((IAutoEditStrategy) strategies.iterator().next()).customizeDocumentCommand(document, command);
            break;

        // make iterator robust against adding/removing strategies from within strategies
        default:
            strategies= new ArrayList(strategies);
            for (final Iterator iterator= strategies.iterator(); iterator.hasNext(); )
                ((IAutoEditStrategy) iterator.next()).customizeDocumentCommand(document, command);

            break;
        }
ArrayList 의 instance 를 피하기 위해 switch-case (if-else 2번)을 사용했다. Instance 의 cost 가 크다는건 알고 있었지만 빈번히 발생하는 경우에 대해서 저렇게 처리하는걸 눈으로 직접 보내 확 와닿는다.
Creative Commons License
Creative Commons License
1 2 3 4 5  ... 31 
분류 전체보기 (31)
FreeTalk (16)
Review (3)
Wish (3)
Tip (6)
1. 2. 3. href="http://cfs.tistory.com/custom/blog/0/2428/skin/images/SyntaxHighlighter.css">
4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 22.