Make Counted and count() return long instead of integer

Description

Currently count() returns an int - should bump that up to a long.

On long overflow, count() should throw ArithmeticException. Also see CLJ-1229.

Environment

None

Activity

Show:
Erik Assum
July 7, 2015, 3:24 PM

Looking at this, there are some problems like in
clojure.lang.RT#toArray line 1658
where you create a new Object array based on the count of a collection.
It seems as if new Object[] takes an int as a param, so one would have to downcast the long to an int for this to work.

Alex Miller
July 7, 2015, 3:39 PM

If you're creating an Object[] greater than 2147483647, you may have other problems.

But yes, this ticket definitely needs a more thorough analysis as to what is affected. In this case, I think if the count is <= Integer/MAX_VALUE, then it should proceed and otherwise should throw an exception.

Erik Assum
July 8, 2015, 2:19 PM

hmmm, this also causes problems wrt java.util.Collection size:
clojure.lang.APersistentSet#size line 164
Where size is specified by

http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html#size()

Assignee

Unassigned

Reporter

Alex Miller

Labels

None

Approval

None

Patch

None

Affects versions

Priority

Major
Configure