Search code examples
javaperformancecookiescookiestore

why the default implemention of CookieStore do not use a tree-like struct?


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) .


Solution

  • 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.