문제

InMemoryCookieStore is the default CookieStore of java , but the main store is a ArrayList, the add and remove op will cost O(n) in worst case ,and index is map , which scan the keySet in order to remove expired cookie. why it use tree(which can represent domain very well,like .b.com is the parent of .a.b.com ) and set (locate Cookie in constant time) .

도움이 되었습니까?

해결책

The CookieStore has a method

List<HttpCookie> getCookies()

so it must maintain, or copy all the cookies on demand. I assume they decided that maintaining a list was the most efficient.

다른 팁

How often do you have so many cookies that O(n) is noticeably larger than O(1) in terms of performance? When choosing between sub-optimization and code manageability, most go for clean, manageable code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top