(patch submitted)
http://gwt-code-reviews.appspot.com/1171801/diff/1/3 File dev/core/src/com/google/gwt/soyc/MakeTopLevelHtmlForPerm.java (right): http://gwt-code-reviews.appspot.com/1171801/diff/1/3#newcode115 dev/core/src/com/google/gwt/soyc/MakeTopLevelHtmlForPerm.java:115: public void freeze() { On 2010/12/01 18:49:25, kathrin wrote:
I've been trying to come up with a way in which you would not have to
call
freeze() and still be "safe". I don't have a good solution -- my only
gripe
here is that if you forget to call freeze(), you won't get any values.
Seems
like the only way to get around this is to call freeze whenever
something is put
in the builder, but that seems very overheady. The only other thing I
can come
up with is for frozen and builder to actually be the same thing (so do
an
in-place reordering when you call freeze -- also see my comment
below). In that
case, if you forget to call freeze, you still have access to the data,
just not
in an optimal way. Do you have any other brilliant ideas?
If you forget to call freeze(), you'll get an NPE - I documented 'frozen' with that information to help someone that might stumble across this. http://gwt-code-reviews.appspot.com/1171801/diff/1/3#newcode126 dev/core/src/com/google/gwt/soyc/MakeTopLevelHtmlForPerm.java:126: } On 2010/12/01 18:49:25, kathrin wrote:
What happens if your count has more than 8 digits?
That would be greater than 99,999,999 strings interned, which seems far fetched, but it isn't at the limit of a 32 bit signed int, so I bumped it to 9 digits and added an assert if it goes over 1 billion entries. http://gwt-code-reviews.appspot.com/1171801/diff/1/3#newcode131 dev/core/src/com/google/gwt/soyc/MakeTopLevelHtmlForPerm.java:131: builder = null; On 2010/12/01 18:49:25, kathrin wrote:
So the only thing I'm wondering is why you're not just using a
TreeMap<String,
Integer> (for frozen) and sorting it by value rather than key (in the
comparator
that you give it). Would that not get you around having to create the
valus
TreeMap?
The comparator for a TreeMap is passed two different keys to compare - you don't have access to the value because the second object might not be in the map yet. The issue here is that I want the list organized first just with a string lookup to keep track of the number of references. Then, I want to order the list by number of references. Finally, I want the key lookup to be a simple string key again, but remembering the order determined by the intervening sort. Thinking about using TreeMap for frozen - I feel it would be overkill because the values are already sorted the way we want, and no changes are allowed to the 'frozen' map after its created. It would just slow down lookups and take more memory. I did refactor the copy in the middle to just use an array and sort it which should be faster and use less memory. http://gwt-code-reviews.appspot.com/1171801/show -- http://groups.google.com/group/Google-Web-Toolkit-Contributors
