MCPcopy Index your code
hub / github.com/clojure/clojure / toArray

Method toArray

src/jvm/clojure/lang/RT.java:1710–1740  ·  view source on GitHub ↗
(Object coll)

Source from the content-addressed store, hash-verified

1708}
1709
1710static public Object[] toArray(Object coll) {
1711 if(coll == null)
1712 return EMPTY_ARRAY;
1713 else if(coll instanceof Object[])
1714 return (Object[]) coll;
1715 else if(coll instanceof Collection)
1716 return ((Collection) coll).toArray();
1717 else if(coll instanceof Iterable) {
1718 ArrayList ret = new ArrayList();
1719 for(Object o : (Iterable)coll)
1720 ret.add(o);
1721 return ret.toArray();
1722 } else if(coll instanceof Map)
1723 return ((Map) coll).entrySet().toArray();
1724 else if(coll instanceof String) {
1725 char[] chars = ((String) coll).toCharArray();
1726 Object[] ret = new Object[chars.length];
1727 for(int i = 0; i < chars.length; i++)
1728 ret[i] = chars[i];
1729 return ret;
1730 }
1731 else if(coll.getClass().isArray()) {
1732 ISeq s = (seq(coll));
1733 Object[] ret = new Object[count(s)];
1734 for(int i = 0; i < ret.length; i++, s = s.next())
1735 ret[i] = s.first();
1736 return ret;
1737 }
1738 else
1739 throw Util.runtimeException("Unable to convert: " + coll.getClass() + " to Object[]");
1740}
1741
1742static public Object[] seqToArray(ISeq seq){
1743 int len = length(seq);

Callers 12

CompilerClass · 0.95
invokeMethod · 0.95
readRecordMethod · 0.95
createMethod · 0.95
numbersMethod · 0.45
FIConstructorMethod · 0.45
parseMethod · 0.45
parseMethod · 0.45
doEmitMethod · 0.45
invokeMethod · 0.45
invokeMethod · 0.45
createMethod · 0.45

Calls 7

seqMethod · 0.95
countMethod · 0.95
nextMethod · 0.95
firstMethod · 0.95
runtimeExceptionMethod · 0.95
addMethod · 0.65
entrySetMethod · 0.45

Tested by 2

numbersMethod · 0.36
FIConstructorMethod · 0.36