[ https://issues.apache.org/jira/browse/LUCENE-2213?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12801160#action_12801160 ]
Dawid Weiss commented on LUCENE-2213: ------------------------------------- Not to be picky, Michael, but is long promotion required here? Would it be easier to see if you overflow into negative integers and if so, set to MAX_VALUE? Another thing -- given the fact that the parameter is an int, you'll never be able to grow beyond Integer.MAX_VALUE (because no int value exists). I'd change the contract to reflect this fact -- if the signature takes two parameters (int currentSize, int expectedAdditions) then it's easy to throw an unchecked exception if you simply can't meet the contract: if (currentSize + expectedAdditions < 0) throw new RuntimeException("Cannot allocate array larger than: " + Integer.MAX_VALUE); When reallocating, you can call it with grow(currentSize, 1), just to make sure the array will be at least one element larger than previously; the method can then make its best effort in estimating the growth ratio, but have a cap on MAX_SIZE before overflowing into negative integers (and avoid looping endlessly when Integer.MAX_VALUE is passed as an input argument). These are just thoughts of course -- I've just finished implementing something like this for another project... > Small improvements to ArrayUtil.getNextSize > ------------------------------------------- > > Key: LUCENE-2213 > URL: https://issues.apache.org/jira/browse/LUCENE-2213 > Project: Lucene - Java > Issue Type: Improvement > Reporter: Michael McCandless > Assignee: Michael McCandless > Priority: Minor > Fix For: 3.1 > > Attachments: LUCENE-2213.patch, LUCENE-2213.patch > > > Spinoff from java-dev thread "Dynamic array reallocation algorithms" started > on Jan 12, 2010. > Here's what I did: > * Keep the +3 for small sizes > * Added 2nd arg = number of bytes per element. > * Round up to 4 or 8 byte boundary (if it's 32 or 64 bit JRE respectively) > * Still grow by 1/8th > * If 0 is passed in, return 0 back > I also had to remove some asserts in tests that were checking the actual > values returned by this method -- I don't think we should test that (it's an > impl. detail). -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org For additional commands, e-mail: java-dev-h...@lucene.apache.org