Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Scala's mutable HashMap allocates a Some\[T] object for every successful get(key) call.

...

We need lots of stacks, and since Scala's general stacks are generic collections, we created our own non-boxing flavors:

  • MStack.Of\[T] - generic
  • MStack.OfInt - stack of Int - non-boxing
  • MStack.OfMaybe\[T] - doesn't create box for the Maybe object. Uses null for Nope, and a regular object reference for One.
    • However, MStackOfMaybe\[Int] will box and unbox the Int

...

If you consider that we have to avoid scala's nice generic collection functional operations like foreach and map, one might be tempted to just use the Iterator\[T] class.

However, if the generic type T here is a value type (e.g., Int, or Long or Boolean) then calling next() will return a boxed object. Whether that box is saved somewhere or is being created and discarded immediately depends on what you are iterating over.

...