dnrajugade / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Consider refactoring CharMatcher to use static factory methods instead of static constants #1193

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In retrospect, we should have done this in the first place, but now it would 
require a serious migration effort.

Among other things, switching to factory methods (which actually usually return 
static constants) -- along the lines of what Hashing does with hash functions 
-- would make it significantly easier to lazily initialize CharMatcher 
constants.

CharMatcher is technically still @Beta, so we could do it...

Original issue reported on code.google.com by lowas...@google.com on 6 Nov 2012 at 8:07

GoogleCodeExporter commented 9 years ago
I'm convinced the static accessors would have been the right way to go. Lesson 
learned. Cost of migration is the question for me now. Also note that not 
*every* one of the constants even deserves to be kept at all.

Original comment by kevinb@google.com on 7 Nov 2012 at 1:38

GoogleCodeExporter commented 9 years ago
It looks like public constants have hardly any use at all, as they're less 
flexible than static accessors.

I wonder if any changes are really needed here given that the culprit 
(`slowGetChars`) is gone in 464b0cf.

It's easy to both keep the constants and defer the initialization; see the 
patch. It costs two indirections at runtime (INVISIBLE -> InvisibleImpl -> 
INSTANCE), which will be inlined, so the only cost is some ugliness.

In case the migration cost is too high, you could simply rewrite the most 
expensive constants like in the patch.

Original comment by Maaarti...@gmail.com on 7 Nov 2012 at 4:09

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 8 Apr 2013 at 6:58

GoogleCodeExporter commented 9 years ago
We tend to think this isn't really worth the effort to change all of the 
callers and go through the deprecation cycle.

Original comment by kak@google.com on 22 Aug 2013 at 11:22

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:13

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:18

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08