Skip to content

Commit

Permalink
Remove unused serialization-related code
Browse files Browse the repository at this point in the history
`LinkedHashMap/Set` extend `DefaultSerializable`, so instances
are not directly serialized, the `DefaultSerializationProxy` is used
instead. Serialization-related code in `LinkedHashMap/Set` is unused.
  • Loading branch information
lrytz committed Dec 2, 2022
1 parent c221509 commit d07b344
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 75 deletions.
42 changes: 3 additions & 39 deletions src/library/scala/collection/mutable/LinkedHashMap.scala
Expand Up @@ -50,16 +50,16 @@ class LinkedHashMap[K, V]

private[collection] def _firstEntry: Entry = firstEntry

@transient protected var firstEntry: Entry = null
protected var firstEntry: Entry = null

@transient protected var lastEntry: Entry = null
protected var lastEntry: Entry = null

/* Uses the same implementation as mutable.HashMap. The hashtable holds the following invariant:
* - For each i between 0 and table.length, the bucket at table(i) only contains keys whose hash-index is i.
* - Every bucket is sorted in ascendant hash order
* - The sum of the lengths of all buckets is equal to contentSize.
*/
@transient private[this] var table = new Array[Entry](tableSizeFor(LinkedHashMap.defaultinitialSize))
private[this] var table = new Array[Entry](tableSizeFor(LinkedHashMap.defaultinitialSize))

private[this] var threshold: Int = newThreshold(table.length)

Expand Down Expand Up @@ -394,42 +394,6 @@ class LinkedHashMap[K, V]
}
}

private[this] def serializeTo(out: java.io.ObjectOutputStream, writeEntry: Entry => Unit): Unit = {
out.writeInt(contentSize)
var cur = firstEntry
while (cur ne null) {
writeEntry(cur)
cur = cur.later
}
}

private def writeObject(out: java.io.ObjectOutputStream): Unit = {
out.defaultWriteObject()
serializeTo(out, { entry =>
out.writeObject(entry.key)
out.writeObject(entry.value)
})
}

private[this] def serializeFrom(in: java.io.ObjectInputStream, readEntry: => (K, V)): Unit = {
val _contentsize = in.readInt()
assert(_contentsize > 0)
clear()
table = new Array(tableSizeFor(_contentsize))
threshold = newThreshold(table.length)

var index = 0
while (index < size) {
addOne(readEntry)
index += 1
}
}

private def readObject(in: java.io.ObjectInputStream): Unit = {
in.defaultReadObject()
serializeFrom(in, (in.readObject().asInstanceOf[K], in.readObject().asInstanceOf[V]))
}

@nowarn("""cat=deprecation&origin=scala\.collection\.Iterable\.stringPrefix""")
override protected[this] def stringPrefix = "LinkedHashMap"
}
Expand Down
39 changes: 3 additions & 36 deletions src/library/scala/collection/mutable/LinkedHashSet.scala
Expand Up @@ -44,16 +44,16 @@ class LinkedHashSet[A]

type Entry = LinkedHashSet.Entry[A]

@transient protected var firstEntry: Entry = null
protected var firstEntry: Entry = null

@transient protected var lastEntry: Entry = null
protected var lastEntry: Entry = null

/* Uses the same implementation as mutable.HashSet. The hashtable holds the following invariant:
* - For each i between 0 and table.length, the bucket at table(i) only contains keys whose hash-index is i.
* - Every bucket is sorted in ascendant hash order
* - The sum of the lengths of all buckets is equal to contentSize.
*/
@transient private[this] var table = new Array[Entry](tableSizeFor(LinkedHashSet.defaultinitialSize))
private[this] var table = new Array[Entry](tableSizeFor(LinkedHashSet.defaultinitialSize))

private[this] var threshold: Int = newThreshold(table.length)

Expand Down Expand Up @@ -270,39 +270,6 @@ class LinkedHashSet[A]
}
}

private[this] def serializeTo(out: java.io.ObjectOutputStream, writeEntry: Entry => Unit): Unit = {
out.writeInt(contentSize)
var cur = firstEntry
while (cur ne null) {
writeEntry(cur)
cur = cur.later
}
}

private def writeObject(out: java.io.ObjectOutputStream): Unit = {
out.defaultWriteObject()
serializeTo(out, { e => out.writeObject(e.key) })
}

private[this] def serializeFrom(in: java.io.ObjectInputStream, readEntry: => A): Unit = {
val _contentsize = in.readInt()
assert(_contentsize > 0)
clear()
table = new Array(tableSizeFor(_contentsize))
threshold = newThreshold(table.length)

var index = 0
while (index < size) {
addOne(readEntry)
index += 1
}
}

private def readObject(in: java.io.ObjectInputStream): Unit = {
in.defaultReadObject()
serializeFrom(in, in.readObject().asInstanceOf[A])
}

@nowarn("""cat=deprecation&origin=scala\.collection\.Iterable\.stringPrefix""")
override protected[this] def stringPrefix = "LinkedHashSet"
}
Expand Down

0 comments on commit d07b344

Please sign in to comment.