8000 Use List.fill instead of range [ci: last-only] by som-snytt · Pull Request #11059 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

Use List.fill instead of range [ci: last-only] #11059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ abstract class ClassfileParser(reader: ReusableInstance[ReusableDataReader]) {
val parentIndex = u2()
val parentName = if (parentIndex == 0) null else pool.getClassName(parentIndex)
val ifaceCount = u2()
val ifaces = for (_ <- List.range(0, ifaceCount)) yield pool.getSuperClassName(index = u2())
val ifaces = List.fill(ifaceCount.toInt)(pool.getSuperClassName(index = u2()))
val completer = new ClassTypeCompleter(clazz.name, jflags, parentName, ifaces)

enterOwnInnerClasses()
Expand Down
8 changes: 4 additions & 4 deletions src/library/scala/collection/Factory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ trait IterableFactory[+CC[_]] extends Serializable {
def newBuilder[A]: Builder[A, CC[A]]

/** Produces a $coll containing the results of some element computation a number of times.
* @param n the number of elements contained in the $coll.
* @param elem the element computation
* @return A $coll that contains the results of `n` evaluations of `elem`.
*/
* @param n the number of elements contained in the $coll.
* @param elem the element computation
* @return A $coll that contains the results of `n` evaluations of `elem`.
*/
def fill[A](n: Int)(elem: => A): CC[A] = from(new View.Fill(n)(elem))

/** Produces a two-dimensional $coll containing the results of some element computation a number of times.
Expand Down
4 changes: 3 additions & 1 deletion src/library/scala/collection/IterableOnce.scala
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
* @return a $coll containing the elements greater than or equal to
* index `from` extending up to (but not including) index `until`
* of this $coll.
* @example
* `List('a', 'b', 'c', 'd', 'e').slice(1, 3) == List('b', 'c')`
*/
def slice(from: Int, until: Int): C

Expand Down Expand Up @@ -1241,7 +1243,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
* @param pf the partial function
* @return an option value containing pf applied to the first
* value for which it is defined, or `None` if none exists.
* @example `Seq("a", 1, 5L).collectFirst({ case x: Int => x*10 }) = Some(10)`
* @example `Seq("a", 1, 5L).collectFirst { case x: Int => x*10 } = Some(10)`
*/
def collectFirst[B](pf: PartialFunction[A, B]): Option[B] = {
// Presumably the fastest way to get in and out of a partial function is for a sentinel function to return itself
Expand Down
11 changes: 0 additions & 11 deletions src/library/scala/collection/immutable/List.scala
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,6 @@ sealed abstract class List[+A]
h
}

/** @inheritdoc
*
* @example {{{
* // Given a list
* val lett 56E6 ers = List('a','b','c','d','e')
*
* // `slice` returns all elements beginning at index `from` and afterwards,
* // up until index `until` (excluding index `until`.)
* letters.slice(1,3) // Returns List('b','c')
* }}}
*/
override def slice(from: Int, until: Int): List[A] = {
val lo = scala.math.max(from, 0)
if (until <= lo || isEmpty) Nil
Expand Down
0