summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/immutable/Range.scala
Commit message (Collapse)AuthorAgeFilesLines
* If Range is sealed, it makes sense to have Range.Inclusive final.Raul Bache2016-06-121-1/+1
|
* Relax the semantics of `Range.lastElement` for internal use.Sébastien Doeraene2016-05-311-11/+10
| | | | | | `lastElement` is only used in code paths where the range is non-empty. It is therefore wasteful to try and give it a sort of sensible value for empty ranges.
* Privatize the deprecated members of `immutable.Range`.Sébastien Doeraene2016-05-311-7/+2
| | | | | | | | | | The implementation of these obscure members of `Range` are uselessly complicated for the purposes of `Range` itself. Making them private will allow to relax their semantics to the specific needs of `Range`, making them simpler, together with the initialization code of `Range`. `terminalElement` becomes dead code and is removed.
* Add since arg to deprecationWarning and use itSimon Ochsenreither2016-05-291-3/+5
|
* Lower-case spelling of @deprecated messagesSimon Ochsenreither2016-05-281-8/+8
|
* Merge pull request #5175 from som-snytt/issue/9656-range-toStringStefan Zeiger2016-05-241-9/+8
|\ | | | | SI-9656 Distinguish Numeric with step type
| * SI-9656 Range.toString distinguishes Numeric stepSteve Robinson2016-05-191-9/+8
| | | | | | | | | | | | | | | | | | | | | | | | For Range and NumericRange, toString will indicate the step if it is not 1. Additionally, indicate empty ranges and ranges which are not "exact". For a "mapped" range, used by `Range.Double`, toString includes the underlying range and the simple type of the step (to distinguish Double from BigDecimal).
* | Make Range.Partial a value classxuwei-k2016-05-171-1/+1
|/
* Make some collection classes final or sealedStefan Zeiger2016-03-231-2/+1
| | | | | | | They were all annotated with `@deprecatedInheritance` in 2.11.0. Some deprecated classes are moved to new source files in order to seal the parent class. The package-private class `DoublingUnrolledBuffer` is moved from `scala.collection.parallel.mutable` to `scala.collection.mutable` in order to seal `UnrolledBuffer`.
* Merge commit '03aaf05' into merge-2.11-to-2.12-sep-22Lukas Rytz2015-09-221-16/+13
|\
| * SI-9388 Fix Range behavior around Int.MaxValueRex Kerr2015-09-191-16/+13
| | | | | | | | | | | | | | | | | | | | terminalElement (the element _after_ the last one!) was used to terminate foreach loops and sums of non-standard instances of Numeric. Unfortunately, this could result in the end wrapping around and hitting the beginning again, making the first element bad. This patch fixes the behavior by altering the loop to end after the last element is encountered. The particular flavor was chosen out of a few possibilities because it gave the best microbenchmarks on both large and small ranges. Test written. While testing, a bug was also uncovered in NumericRange, and was also fixed. In brief, the logic around sum is rather complex since division is not unique when you have overflow. Floating point has its own complexities, too. Also updated incorrect test t4658 that insisted on incorrect answers (?!) and added logic to make sure it at least stays self-consistent, and fixed the range.scala test which used the same wrong (overflow-prone) formula that the Range collection did.
* | Merge remote-tracking branch 'origin/2.11.x' into ↵Jason Zaugg2015-07-231-1/+1
|\| | | | | | | merge/2.11.x-to-2.12.x-20152307
| * SI-9406 fix doc for Range.takeRightSeth Tisue2015-07-181-1/+1
| |
* | Merge commit 'eb15950' into merge/2.11.x-to-2.12.x-20150129Jason Zaugg2015-01-291-1/+7
|\|
| * SI-6192 Range: to, until and end are confusingRex Kerr2014-09-301-1/+7
| | | | | | | | Added some documentation explaining what the role of `end` is.
* | SI-8819 Range slice does not return a RangeRex Kerr2014-11-251-1/+18
|/ | | | Added an override to the `slice` method that creates a `Range`. No tests (except verifying by hand that it solves the bug); scala-collections-laws found and will test this.
* SI-8738 Regression in range equalityRex Kerr2014-07-201-9/+10
| | | | | | Missed the case of comparing a non-empty range to an empty one. Fixed by checking nonEmpty/isEmpty on other collection. Added a test to verify the behavior.
* Reasonable Range operations consistently work when overfull.Rex Kerr2014-02-091-24/+105
| | | | | | Operations are reasonable when they don't require indexing or conversion into a collection. These include head, tail, init, last, drop, take, dropWhile, takeWhile, dropRight, takeRight, span. Tests added also to verify the new behavior.
* SI-6736 Range.contains is wrongRex Kerr2014-02-091-7/+11
| | | | Removed once-used private method that was calculating ranges in error and corrected the contains method (plus improved performance).
* SI-7443 Use typeclass instance for {Range,NumericRange}.sumDmitry Petrashko2013-12-291-3/+18
| | | | | | | | Previously both Range and NumeriRange used formula for sum of elements of arithmetic series and thus always assumed that provided Numeric is regular one. Bug is now fixed by conservatively checking if Numeric is one of default ones and the formula still holds.
* Removing deprecated code.Paul Phillips2013-11-181-16/+0
| | | | | Code which has been deprecated since 2.10.0 and which allowed for straightforward removal.
* Collections library tidying and deprecation. Separate parts are listed below.Rex Kerr2013-11-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Collections library tidying, part one: scripting. Everything in scala.collection.scripting is deprecated now, along with the << method that is implemented in a few other classes. Scripting does not seem used at all, and anyone who did can easily write a wrapper that does the same thing. Deprecated *Proxy collections. The only place proxies were used in the library was in swing.ListView, and that was easy to change to a lazy val. Proxy itself is used in ScalaNumberProxy and such, so it was left undeprecated. Deprecated Synchronized* traits from collections. Synchronizability does not compose well, and it requires careful examination of every method (which has not actually been done). Places where the Scala codebase needs to be fixed (eventually) include: scala.reflect.internal.util.Statistics$QuantMap scala.tools.nsc.interactive.Global (several places) Deprecated LinkedList (including Double- and -Like variants). Interface is idiosyncratic and dangerously low-level. Although some low-level functionality of this sort would be useful, this doesn't seem to be the ideal implementation. Also deprecated the extractFirst method in Queue as it exposes LinkedList. Cannot shift internal representations away from LinkedList at this time because of that method. Deprecated non-finality of several toX collection methods. Improved documentation of most toX collection methods to describe what the expectation is for their behavior. Additionally deprecated overriding of - toIterator in IterableLike (should always forward to iterator) - toTraversable in TraversableLike (should always return self) - toIndexedSeq in immutable.IndexedSeq (should always return self) - toMap in immutable.Map (should always return self) - toSet in immutable.Set (should always return self) Did not do anything with IterableLike.toIterable or Seq/SeqLike.toSeq since for some odd reason immutable.Range overrides those. Deprecated Forwarders from collections. Forwarding, without an automatic mechanism to keep up to date with changes in the forwarded class, is inherently unreliable. Absent a mechanism to keep current, they're deprecated. ListBuffer is the only class in the collections library that uses forwarders, and that functionality can be rolled into ListBuffer itself. Deprecating immutable set/map adaptors. They're a bad idea (barring compiler support) for the same reason that all the other adaptors are a bad idea: they get out of date and probably have a variety of performance bugs. Deprecated inheritance from leaf classes in immutable collections. Inheriting from leaf-classes in immutable collections is rarely a good idea since whenever you use any interesting collections method you'll revert to the original class. Also, the methods are often designed to work with only particular behavior, and an override would be difficult (at best) to make work. Fortunately, people seem to have realized this and there are few to no cases of people extending PagedSeq and TreeSet and the like. Note that in many cases the classes will become sealed not final. Deprecated overriding of methods and inheritance from various mutable collections. Some mutable collections seem unsuited for overriding since to override anything interesting you would need vast knowledge of internal data structures and/or access to private methods. These include - ArrayBuilder.ofX classes. - ArrayOps - Some methods of BitSet (moved others from private to protected final) - Some methods of HashTable and FlatHashTable - Some methods of HashMap and HashSet (esp += and -= which just forward) - Some methods of other maps and sets (LinkedHashX, ListMap, TreeSet) - PriorityQueue - UnrolledBuffer This is a somewhat aggressive deprecation, the theory being better to try it out now and back off if it's too much than not attempt the change and be stuck with collections that can neither be safely inherited nor have implementation details changed. Note that I have made no changes--in this commit--which would cause deprecation warnings in any of the Scala projects available on Maven (at least as gathered by Adriaan). There are deprecation warnings induced within the library (esp. for classes/traits that should become static) and the compiler. I have not attempted to fix all the deprecations in the compiler as some of them touch the IDE API (but these mostly involved Synchronized which is inherently unsafe, so this should be fixed eventually in coordination with the IDE code base(s)). Updated test checks to include new deprecations. Used a higher level implementation for messages in JavapClass.
* Cull extraneous whitespace.Paul Phillips2013-09-181-2/+2
| | | | | | | | | | | | | | | | | | | | | One last flurry with the broom before I leave you slobs to code in your own filth. Eliminated all the trailing whitespace I could manage, with special prejudice reserved for the test cases which depended on the preservation of trailing whitespace. Was reminded I cannot figure out how to eliminate the trailing space on the "scala> " prompt in repl transcripts. At least reduced the number of such empty prompts by trimming transcript code on the way in. Routed ConsoleReporter's "printMessage" through a trailing whitespace stripping method which might help futureproof against the future of whitespace diseases. Deleted the up-to-40 lines of trailing whitespace found in various library files. It seems like only yesterday we performed whitespace surgery on the whole repo. Clearly it doesn't stick very well. I suggest it would work better to enforce a few requirements on the way in.
* SI-6747 Deprecate Range#{numRange,last,terminal}Element{s,}Simon Ochsenreither2013-06-091-0/+3
| | | | There are already better replacements which expose less surprising behaviour.
* Merge pull request #2470 from ihji/masterPaul Phillips2013-05-111-2/+2
|\ | | | | SI-7432 Range.min should throw NoSuchElementException on empty range
| * SI-7432 Range.min should throw NoSuchElementException on empty rangeHeejong Lee2013-04-301-2/+2
| | | | | | | | | | For consistency, range.max and range.min should throw NoSuchElementException on an empty range.
* | Absolutized paths involving the scala package.Paul Phillips2013-05-031-1/+2
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Confusing, now-it-happens now-it-doesn't mysteries lurk in the darkness. When scala packages are declared like this: package scala.collection.mutable Then paths relative to scala can easily be broken via the unlucky presence of an empty (or nonempty) directory. Example: // a.scala package scala.foo class Bar { new util.Random } % scalac ./a.scala % mkdir util % scalac ./a.scala ./a.scala:4: error: type Random is not a member of package util new util.Random ^ one error found There are two ways to play defense against this: - don't use relative paths; okay sometimes, less so others - don't "opt out" of the scala package This commit mostly pursues the latter, with occasional doses of the former. I created a scratch directory containing these empty directories: actors annotation ant api asm beans cmd collection compat concurrent control convert docutil dtd duration event factory forkjoin generic hashing immutable impl include internal io logging macros man1 matching math meta model mutable nsc parallel parsing partest persistent process pull ref reflect reify remote runtime scalap scheduler script swing sys text threadpool tools transform unchecked util xml I stopped when I could compile the main src directories even with all those empties on my classpath.
* Name boolean arguments in src/library.Jason Zaugg2013-03-051-1/+1
|
* fusion of loops in Range.foreach() and Range.validateRangeBoundaries()Miguel Garcia2012-12-281-8/+14
| | | | | | This commit allows closure elimination in more cases. The non-inlined case also benefits from saving a Range.validateRangeBoundaries() invocation. Before this commit, the closure argument to Range.foreach() escaped to Range.validateRangeBoundaries(). As a consequence, closure elimination required inlining both of them. Given that the current optimizer duplicates a closure body whenever that closure's apply() is invoked, the resulting code size taxed the JIT compiler. In particular when apply() delegates to a specialized version, or when a bridge apply() stands in the way.
* Merge branch 'merge-wip-into-2.10.x' into merge-2.10-into-masterPaul Phillips2012-12-111-1/+0
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * merge-wip-into-2.10.x: (44 commits) Cleanups of reifyBoundTerm and reifyBoundType SI-5841 reification of renamed imports Share the empty LinkedList between first0/last0. SI-4922 Show default in Scaladoc for generic methods. SI-6614 Test case for fixed ArrayStack misconduct. SI-6690 Release reference to last dequeued element. SI-5789 Use the ReplTest framework in the test SI-5789 Checks in the right version of the test SI-5789 Removes assertion about implclass flag in Mixin.scala SI-6766 Makes the -Pcontinuations:enable flag a project specific preference more ListOfNil => Nil DummyTree => CannotHaveAttrs evicts assert(false) from the compiler introduces global.pendingSuperCall refactors handling of parent types unifies approaches to call analysis in TreeInfo TypeApply + Select and their type-level twins SI-6696 removes "helper" tree factory methods SI-6766 Create a continuations project in eclipse Now the test suite runs MIMA for compatibility testing. ... Conflicts: src/compiler/scala/reflect/reify/codegen/GenUtils.scala src/compiler/scala/tools/nsc/ast/Trees.scala src/compiler/scala/tools/nsc/backend/icode/GenICode.scala src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala src/compiler/scala/tools/nsc/typechecker/Contexts.scala src/compiler/scala/tools/nsc/typechecker/Namers.scala src/compiler/scala/tools/nsc/typechecker/Typers.scala src/eclipse/scala-compiler/.classpath src/eclipse/scalap/.classpath src/reflect/scala/reflect/internal/StdNames.scala src/reflect/scala/reflect/internal/TreeInfo.scala
| * SI-5678 Bad return type for [Use Case] docs in RangeJean-Remi Desjardins2012-11-271-1/+0
| | | | | | | | | | | | | | | | | | | | Many [Use Case] example in Range such as the one associated to the union method document that the method returns a Range which is just plain false. Example: val ran1 = Range(1,3) val ran2 = Range(54, 57) val result = ran1.union(ran2) // This is a perfectly valid use case yet obviously cannot be represented as a Range
* | Merge commit 'refs/pull/1574/head' into merge-210Paul Phillips2012-11-051-1/+1
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit 'refs/pull/1574/head': (24 commits) Fixing issue where OSGi bundles weren't getting used for distribution. Fixes example in Type.asSeenFrom Fix for SI-6600, regression with ScalaNumber. SI-6562 Fix crash with class nested in @inline method Brings copyrights in Scaladoc footer and manpage up-to-date, from 2011/12 to 2013 Brings all copyrights (in comments) up-to-date, from 2011/12 to 2013 SI-6606 Drops new icons in, replaces abstract types placeholder icons SI-6132 Revisited, cleaned-up, links fixed, spelling errors fixed, rewordings Labeling scala.reflect and scala.reflect.macros experimental in the API docs Typo-fix in scala.concurrent.Future, thanks to @pavelpavlov Remove implementation details from Position (they are still under reflection.internal). It probably needs more cleanup of the api wrt to ranges etc but let's leave it for later SI-6399 Adds API docs for Any and AnyVal Removing actors-migration from main repository so it can live on elsewhere. Fix for SI-6597, implicit case class crasher. SI-6578 Harden against synthetics being added more than once. SI-6556 no assert for surprising ctor result type Removing actors-migration from main repository so it can live on elsewhere. Fixes SI-6500 by making erasure more regular. Modification to SI-6534 patch. Fixes SI-6559 - StringContext not using passed in escape function. ... Conflicts: src/actors-migration/scala/actors/migration/StashingActor.scala src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala src/compiler/scala/tools/nsc/settings/AestheticSettings.scala src/compiler/scala/tools/nsc/transform/Erasure.scala src/library/scala/Application.scala src/library/scala/collection/immutable/GenIterable.scala.disabled src/library/scala/collection/immutable/GenMap.scala.disabled src/library/scala/collection/immutable/GenSeq.scala.disabled src/library/scala/collection/immutable/GenSet.scala.disabled src/library/scala/collection/immutable/GenTraversable.scala.disabled src/library/scala/collection/mutable/GenIterable.scala.disabled src/library/scala/collection/mutable/GenMap.scala.disabled src/library/scala/collection/mutable/GenSeq.scala.disabled src/library/scala/collection/mutable/GenSet.scala.disabled src/library/scala/collection/mutable/GenTraversable.scala.disabled src/library/scala/collection/parallel/immutable/ParNumericRange.scala.disabled
| * Brings all copyrights (in comments) up-to-date, from 2011/12 to 2013Heather Miller2012-11-021-1/+1
| |
* | Fixes SI-6521, overrides Range#head to be fasterDavid Hall2012-10-121-0/+1
|/
* Removed many @inline annotations and final modifiers.Paul Phillips2012-09-181-3/+3
| | | | | | | | | | | | It is my belief that these @inlines and finals landed between unhelpful and harmful. I am sure this will be disputed in some cases. It's too much and too difficult to measure except in the aggregate unless we have specific @inline sites to discuss. I don't know upon whom the burden of proof lies. I think we should err on the side given here, since there is no evidence of any consistent rationale being applied and it is easy to verify the negative impact scala compiler inlining can have on hotspot's far more sophisticated inlining.
* Eliminate breaking relative names in source.Paul Phillips2012-09-141-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These things are killing me. Constructions like package scala.foo.bar.baz import foo.Other DO NOT WORK in general. Such files are not really in the "scala" package, because it is not declared package scala package foo.bar.baz And there is a second problem: using a relative path name means compilation will fail in the presence of a directory of the same name, e.g. % mkdir reflect % scalac src/reflect/scala/reflect/internal/util/Position.scala src/reflect/scala/reflect/internal/util/Position.scala:9: error: object ClassTag is not a member of package reflect import reflect.ClassTag ^ src/reflect/scala/reflect/internal/util/Position.scala:10: error: object base is not a member of package reflect import reflect.base.Attachments ^ As a rule, do not use relative package paths unless you have explicitly imported the path to which you think you are relative. Better yet, don't use them at all. Unfortunately they mostly work because scala variously thinks everything scala.* is in the scala package and/or because you usually aren't bootstrapping and it falls through to an existing version of the class already on the classpath. Making the paths explicit is not a complete solution - in particular, we remain enormously vulnerable to any directory or package called "scala" which isn't ours - but it greatly limts the severity of the problem.
* Fixes SI-5857.Aleksandar Prokopec2012-06-061-1/+13
| | | | | | | | Override `min` and `max` in `Range` and `NumericRange` to check if a default `Ordering` for the numeric type in question is used. If so, bypass traversal and compute the minimum or maximum element.
* Fixes SI-5344.Hubert Plociniczak2012-05-081-3/+3
|
* Removed all the imports of the bridge annotation.Paul Phillips2012-04-281-1/+0
| | | | Now that nothing uses it.
* Removed a few more @deprecated members.Paul Phillips2012-04-281-3/+0
| | | | | The ones which remain I'm not removing on purpose, as I know from experience it's more trouble than it's yet worth.
* Removes @bridge methods.Simon Ochsenreither2012-04-281-4/+1
|
* Whitespace commit.Paul Phillips2012-02-291-7/+6
| | | | | | | Removed all the trailing whitespace to make eugene happier. Will try to keep it that way by protecting at the merge level. Left the tabs in place because they can't be uniformly changed to spaces, some are 2, some are 4, some are 8, whee.
* Cleaner range counting.Paul Phillips2012-01-241-9/+27
| | | | Plus a big unit test I had lying around.
* Intermediate range commit.Paul Phillips2011-12-161-106/+79
| | | | | | | This is not a long-term implementation - I haven't even benchmarked it -- don't worry. I did find a fairly gross bug in the version I checked in a few days ago so I wanted to erase that from the repository memory for the weekend.
* Range.foreach optimization.Paul Phillips2011-12-121-12/+77
| | | | | | | | | | | This makes code like 0 to 100 foreach (x += _) as fast as (often faster than, in fact) a while loop. See the comment in Range for the gory details. More investigation should be done regarding total impact on inlining behavior. Review by @odersky.
* Update scaladoc links to collections overview.Josh Marcus2011-12-061-1/+1
| | | | | | Change scaladoc links in collection classes to point at re-formatted Collections Overview on docs.scala-lang.org. Fix minor typo: s/Ummutable/Immutable
* Enhanced scaladoc of collection classes with links to the relevant pages of ↵Josh Marcus2011-12-051-0/+3
| | | | "The Scala 2.8 Collections API" overview.
* Makes Range#sum an O(1) operation instead of an O(n) one.Simon Ochsenreither2011-12-021-0/+7
| | | | Partially fixes SI-4658. NumericRange stays slow, thanks to the brilliant idea that Numeric doesn't need a division operation.
* Dropped about 1.5 Mb off scala-library.jar.Paul Phillips2011-11-071-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit and the two subsequent commits were contributed by: Todd Vierling <tv@duh.org>. I combined some commits and mangled his commit messages, but all the credit is his. This pursues the same approach to classfile reduction seen in r19989 when AbstractFunctionN was introduced, but applies it to the collections. Thanks to -Xlint it's easy to verify that the private types don't escape. Design considerations as articulated by Todd: * Don't necessarily create concrete types for _everything_. Where a subtrait only provides a few additional methods, don't bother; instead, use the supertrait's concrete class and retain the "with". For example, "extends AbstractSeq[A] with LinearSeq[A]". * Examine all classes with .class file size greater than 10k. Named classes and class names ending in $$anon$<num> are candidates for analysis. * If a return type is currently inferred where an anon subclass would be returned, make the return type explicit. Don't allow the library-private abstract classes to leak into the public namespace [and scaladoc].
* Fix for unfortunate bug in Range.init.Paul Phillips2011-06-301-1/+1
|