Skip to content

Commit 0dafe20

Browse files
committed
make private[this] if possible
private (not private[this]) val and var generate accessor methods. This change reduce class file size
1 parent 5db2e6c commit 0dafe20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+174
-174
lines changed

src/library/scala/App.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ trait App extends DelayedInit {
4545
*/
4646
protected final def args: Array[String] = _args
4747

48-
private var _args: Array[String] = _
48+
private[this] var _args: Array[String] = _
4949

50-
private val initCode = new ListBuffer[() => Unit]
50+
private[this] val initCode = new ListBuffer[() => Unit]
5151

5252
/** The init hook. This saves all initialization code for execution within `main`.
5353
* This method is normally never called directly from user code.

src/library/scala/Console.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ import scala.util.DynamicVariable
123123
*
124124
*/
125125
object Console extends AnsiColor {
126-
private val outVar = new DynamicVariable[PrintStream](java.lang.System.out)
127-
private val errVar = new DynamicVariable[PrintStream](java.lang.System.err)
128-
private val inVar = new DynamicVariable[BufferedReader](
126+
private[this] val outVar = new DynamicVariable[PrintStream](java.lang.System.out)
127+
private[this] val errVar = new DynamicVariable[PrintStream](java.lang.System.err)
128+
private[this] val inVar = new DynamicVariable[BufferedReader](
129129
new BufferedReader(new InputStreamReader(java.lang.System.in)))
130130

131131
protected def setOutDirect(out: PrintStream): Unit = outVar.value = out

src/library/scala/Enumeration.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ abstract class Enumeration (initial: Int) extends Serializable {
9999

100100
/** The mapping from the integer used to identify values to their
101101
* names. */
102-
private val nmap: mutable.Map[Int, String] = new mutable.HashMap
102+
private[this] val nmap: mutable.Map[Int, String] = new mutable.HashMap
103103

104104
/** The values of this enumeration as a set.
105105
*/
@@ -122,11 +122,11 @@ abstract class Enumeration (initial: Int) extends Serializable {
122122

123123
/** The highest integer amongst those used to identify values in this
124124
* enumeration. */
125-
private var topId = initial
125+
private[this] var topId = initial
126126

127127
/** The lowest integer amongst those used to identify values in this
128128
* enumeration, but no higher than 0. */
129-
private var bottomId = if(initial < 0) initial else 0
129+
private[this] var bottomId = if(initial < 0) initial else 0
130130

131131
/** The one higher than the highest integer amongst those used to identify
132132
* values in this enumeration. */

src/library/scala/Product.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ trait Product extends Any with Equals {
3636
* @return in the default implementation, an `Iterator[Any]`
3737
*/
3838
def productIterator: Iterator[Any] = new scala.collection.AbstractIterator[Any] {
39-
private var c: Int = 0
40-
private val cmax = productArity
39+
private[this] var c: Int = 0
40+
private[this] val cmax = productArity
4141
def hasNext = c < cmax
4242
def next() = { val result = productElement(c); c += 1; result }
4343
}

src/library/scala/Symbol.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ private[scala] abstract class UniquenessCache[K, V >: Null]
4545
import java.util.WeakHashMap
4646
import java.util.concurrent.locks.ReentrantReadWriteLock
4747

48-
private val rwl = new ReentrantReadWriteLock()
49-
private val rlock = rwl.readLock
50-
private val wlock = rwl.writeLock
51-
private val map = new WeakHashMap[K, WeakReference[V]]
48+
private[this] val rwl = new ReentrantReadWriteLock()
49+
private[this] val rlock = rwl.readLock
50+
private[this] val wlock = rwl.writeLock
51+
private[this] val map = new WeakHashMap[K, WeakReference[V]]
5252

5353
protected def valueFromKey(k: K): V
5454
protected def keyFromValue(v: V): Option[K]

src/library/scala/collection/BitSet.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ trait BitSetOps[+C <: BitSet with BitSetOps[C]]
9797
def iterator: Iterator[Int] = iteratorFrom(0)
9898

9999
def iteratorFrom(start: Int): Iterator[Int] = new AbstractIterator[Int] {
100-
private var current = start
101-
private val end = nwords * WordLength
100+
private[this] var current = start
101+
private[this] val end = nwords * WordLength
102102
def hasNext: Boolean = {
103103
while (current != end && !self.contains(current)) current += 1
104104
current != end

src/library/scala/collection/IndexedSeq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ trait IndexedSeqOps[+A, +CC[_], +C] extends Any with SeqOps[A, CC, C] { self =>
1717
def iterator: Iterator[A] = view.iterator
1818

1919
override def reverseIterator: Iterator[A] = new AbstractIterator[A] {
20-
private var i = self.length
20+
private[this] var i = self.length
2121
def hasNext: Boolean = 0 < i
2222
def next(): A =
2323
if (0 < i) {

src/library/scala/collection/IndexedSeqView.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ object IndexedSeqView {
2323

2424
@SerialVersionUID(3L)
2525
private final class IndexedSeqViewIterator[A](self: IndexedSeqView[A]) extends AbstractIterator[A] with Serializable {
26-
private var current = 0
26+
private[this] var current = 0
2727
override def knownSize: Int = self.size - current
2828
def hasNext = current < self.size
2929
def next(): A = {

src/library/scala/collection/Iterator.scala

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
103103
* @note Reuse: $consumesAndProducesIterator
104104
*/
105105
def buffered: BufferedIterator[A] = new AbstractIterator[A] with BufferedIterator[A] {
106-
private var hd: A = _
107-
private var hdDefined: Boolean = false
106+
private[this] var hd: A = _
107+
private[this] var hdDefined: Boolean = false
108108

109109
def head: A = {
110110
if (!hdDefined) {
@@ -308,13 +308,13 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
308308
def scanLeft[B](z: B)(op: (B, A) => B): Iterator[B] = new AbstractIterator[B] {
309309
// We use an intermediate iterator that iterates through the first element `z`
310310
// and then that will be modified to iterate through the collection
311-
private var current: Iterator[B] =
311+
private[this] var current: Iterator[B] =
312312
new AbstractIterator[B] {
313313
def hasNext: Boolean = true
314314
def next(): B = {
315315
// Here we change our self-reference to a new iterator that iterates through `self`
316316
current = new AbstractIterator[B] {
317-
private var acc = z
317+
private[this] var acc = z
318318
def next(): B = {
319319
acc = op(acc, self.next())
320320
acc
@@ -381,8 +381,8 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
381381
def filterNot(p: A => Boolean): Iterator[A] = filterImpl(p, isFlipped = true)
382382

383383
private[collection] def filterImpl(p: A => Boolean, isFlipped: Boolean): Iterator[A] = new AbstractIterator[A] {
384-
private var hd: A = _
385-
private var hdDefined: Boolean = false
384+
private[this] var hd: A = _
385+
private[this] var hdDefined: Boolean = false
386386

387387
def hasNext: Boolean = hdDefined || {
388388
do {
@@ -457,9 +457,9 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
457457
*/
458458
def distinctBy[B](f: A => B): Iterator[A] = new AbstractIterator[A] {
459459

460-
private val traversedValues = mutable.HashSet.empty[B]
461-
private var nextElementDefined: Boolean = false
462-
private var nextElement: A = _
460+
private[this] val traversedValues = mutable.HashSet.empty[B]
461+
private[this] var nextElementDefined: Boolean = false
462+
private[this] var nextElement: A = _
463463

464464
def hasNext: Boolean = {
465465
@tailrec
@@ -496,7 +496,7 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
496496
}
497497

498498
def flatMap[B](f: A => IterableOnce[B]): Iterator[B] = new AbstractIterator[B] {
499-
private var myCurrent: Iterator[B] = Iterator.empty
499+
private[this] var myCurrent: Iterator[B] = Iterator.empty
500500
private def current = {
501501
while (!myCurrent.hasNext && self.hasNext)
502502
myCurrent = f(self.next()).iterator
@@ -514,7 +514,7 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
514514
@`inline` final def ++ [B >: A](xs: => IterableOnce[B]): Iterator[B] = concat(xs)
515515

516516
def take(n: Int): Iterator[A] = new AbstractIterator[A] {
517-
private var i = 0
517+
private[this] var i = 0
518518
def hasNext = self.hasNext && i < n
519519
def next() =
520520
if (hasNext) {
@@ -525,9 +525,9 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
525525
}
526526

527527
def takeWhile(p: A => Boolean): Iterator[A] = new AbstractIterator[A] {
528-
private var hd: A = _
529-
private var hdDefined: Boolean = false
530-
private var tail: Iterator[A] = self
528+
private[this] var hd: A = _
529+
private[this] var hdDefined: Boolean = false
530+
private[this] var tail: Iterator[A] = self
531531

532532
def hasNext = hdDefined || tail.hasNext && {
533533
hd = tail.next()
@@ -779,8 +779,8 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
779779
*/
780780
def patch[B >: A](from: Int, patchElems: Iterator[B], replaced: Int): Iterator[B] =
781781
new AbstractIterator[B] {
782-
private var origElems = self
783-
private var i = if (from > 0) from else 0 // Counts down, switch to patch on 0, -1 means use patch first
782+
private[this] var origElems = self
783+
private[this] var i = if (from > 0) from else 0 // Counts down, switch to patch on 0, -1 means use patch first
784784
def hasNext: Boolean = {
785785
if (i == 0) {
786786
origElems = origElems drop replaced
@@ -841,7 +841,7 @@ object Iterator extends IterableFactory[Iterator] {
841841
@`inline` final def empty[T]: Iterator[T] = _empty
842842

843843
def single[A](a: A): Iterator[A] = new AbstractIterator[A] {
844-
private var consumed: Boolean = false
844+
private[this] var consumed: Boolean = false
845845
def hasNext = !consumed
846846
def next() = if (consumed) empty.next() else { consumed = true; a }
847847
}
@@ -864,7 +864,7 @@ object Iterator extends IterableFactory[Iterator] {
864864
* @return An iterator that produces the results of `n` evaluations of `elem`.
865865
*/
866866
override def fill[A](len: Int)(elem: => A): Iterator[A] = new AbstractIterator[A] {
867-
private var i = 0
867+
private[this] var i = 0
868868
def hasNext: Boolean = i < len
869869
def next(): A =
870870
if (hasNext) { i += 1; elem }
@@ -878,7 +878,7 @@ object Iterator extends IterableFactory[Iterator] {
878878
* @return An iterator that produces the values `f(0), ..., f(n -1)`.
879879
*/
880880
override def tabulate[A](end: Int)(f: Int => A): Iterator[A] = new AbstractIterator[A] {
881-
private var i = 0
881+
private[this] var i = 0
882882
def hasNext: Boolean = i < end
883883
def next(): A =
884884
if (hasNext) { val result = f(i); i += 1; result }
@@ -899,7 +899,7 @@ object Iterator extends IterableFactory[Iterator] {
899899
* @return the iterator producing the infinite sequence of values `start, start + 1 * step, start + 2 * step, ...`
900900
*/
901901
def from(start: Int, step: Int): Iterator[Int] = new AbstractIterator[Int] {
902-
private var i = start
902+
private[this] var i = start
903903
def hasNext: Boolean = true
904904
def next(): Int = { val result = i; i += step; result }
905905
}
@@ -921,8 +921,8 @@ object Iterator extends IterableFactory[Iterator] {
921921
*/
922922
def range(start: Int, end: Int, step: Int): Iterator[Int] = new AbstractIterator[Int] {
923923
if (step == 0) throw new IllegalArgumentException("zero step")
924-
private var i = start
925-
private var hasOverflowed = false
924+
private[this] var i = start
925+
private[this] var hasOverflowed = false
926926
def hasNext: Boolean = {
927927
(step <= 0 || i < end) && (step >= 0 || i > end) && !hasOverflowed
928928
}
@@ -1045,8 +1045,8 @@ object Iterator extends IterableFactory[Iterator] {
10451045
* Lazily skip to start on first evaluation. Avoids daisy-chained iterators due to slicing.
10461046
*/
10471047
private[scala] final class SliceIterator[A](val underlying: Iterator[A], start: Int, limit: Int) extends AbstractIterator[A] {
1048-
private var remaining = limit
1049-
private var dropping = start
1048+
private[this] var remaining = limit
1049+
private[this] var dropping = start
10501050
@inline private def unbounded = remaining < 0
10511051
private def skip(): Unit =
10521052
while (dropping > 0) {

0 commit comments

Comments
 (0)