svendiedrichsen / jollyday

Jollyday - A holiday API
Other
189 stars 114 forks source link

Try to get the value first to avoid creating a lambda #68

Closed guidomedina closed 6 years ago

guidomedina commented 6 years ago

Try to get the value first which is most likely to be cached to avoid creating a lambda.

Similar to: https://github.com/quickfix-j/quickfixj/blob/master/quickfixj-core/src/main/java/org/quickfixj/SimpleCache.java

I was going to submit this PR yesterday but I was so busy that got distracted and forgot.

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 82.412% when pulling bcdc6d48d15a700f02917b1c91e9e96046b1c698 on guidomedina:master into 249bf33a8cbb5eab517d4ff5adc4037882b115c4 on svendiedrichsen:master.

svendiedrichsen commented 6 years ago

@guidomedina I mad some comments in the code.

guidomedina commented 6 years ago

@svendiedrichsen I can't see your comments, I don't know what to do, I even tried from an incognito session and your comments are not there.

svendiedrichsen commented 6 years ago

@guidomedina If you are logged in you can see them right in this conversation or when you are looking at the 'Files changed' tab.

svendiedrichsen commented 6 years ago

Comments: 1) What is the reason for calling getDeclaredConstructor Method? 2) Why check cache first? Isn't this the exact purpose of the computIfAbsent Method?

guidomedina commented 6 years ago

If the function were static and not a lambda dynamically created the difference would be very minimal; for caches with high reading pattern vs write calling first get is more effective.

For example, in SimpleCache there is a pre-defined loading function for the whole cache and not one created per key.

svendiedrichsen commented 6 years ago

Ok, sounds good to me then. Thanks for the work.