Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java ArrayList 1.7

Name: Anonymous 2011-11-30 10:39

http://www.docjar.com/html/api/java/util/ArrayList.java.html


  374       /**
  375        * Returns the element at the specified position in this list.
  376        *
  377        * @param  index index of the element to return
  378        * @return the element at the specified position in this list
  379        * @throws IndexOutOfBoundsException {@inheritDoc}
  380        */
  381       public E get(int index) {
  382           rangeCheck(index);
  383  
  384           return elementData(index);
  385       }

 596       /**
  597        * Checks if the given index is in range.  If not, throws an appropriate
  598        * runtime exception.  This method does *not* check if the index is
  599        * negative: It is always used immediately prior to an array access,
  600        * which throws an ArrayIndexOutOfBoundsException if index is negative.
  601        */
  602       private void rangeCheck(int index) {
  603           if (index >= size)
  604               throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  605       }



What's the point of having a range check if it only checks if the index is >= to the size and not if it's < 0. This seems stupid and a waste of a method call.



  171       /**
  172        * Increases the capacity of this <tt>ArrayList</tt> instance, if
  173        * necessary, to ensure that it can hold at least the number of elements
  174        * specified by the minimum capacity argument.
  175        *
  176        * @param   minCapacity   the desired minimum capacity
  177        */
  178       public void ensureCapacity(int minCapacity) {
  179           if (minCapacity > 0)
  180               ensureCapacityInternal(minCapacity);
  181       }
  182  
  183       private void ensureCapacityInternal(int minCapacity) {
  184           modCount++;
  185           // overflow-conscious code
  186           if (minCapacity - elementData.length > 0)
  187               grow(minCapacity);
  188       }


ensureCapacity is never called, yet they have it in the class.


BLOAT

Name: Anonymous 2011-11-30 22:21

>>19
>Does the Java compiler/interpreter inline such methods, or only when they're declared final? (Or not even then?)
I cannot say. I think that the compiler (.java -> .class) does not do it, since it is really basic. Most optimizations are done at runtime in the JVM, and since there is lot of work on it, I think it may inline those functions.

See this: http://shootout.alioth.debian.org/u64q/which-programming-languages-are-fastest.php?gcc=on&gpp=on&java=on&calc=chart (quad-core) or this: http://shootout.alioth.debian.org/u64/which-programming-languages-are-fastest.php?gcc=on&gpp=on&java=on&calc=chart (mono-core): Java is very good, but not on the level of C or C++.
However, I'm currently working at a company that produces a OLAP DBMS for financial companies, and it's highly multi-threaded (at clients' we make it run on computers with 50 or 100 cores, and hundreds of GO of RAM). It performs far better than the competitors' products, who are mostly in C or C++, thanks to the ease of multithreading and parallelizing in Java.
Yes, faster than C.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List