Commit Graph

67 Commits

Author SHA1 Message Date
Max Moiseev
1600c52822 [stdlib] Constraining AnySequence.init
... to only allow sequences where SubSequence.SubSequence ==
SubSequence. See swift-evolution proposal
https://github.com/apple/swift-evolution/blob/master/proposals/0014-constrained-AnySequence.md
for more details.
2016-01-06 12:25:09 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Dmitri Gribenko
b1fdf56f5c stdlib: mark _preprocessingPass with @noescape 2015-12-23 14:56:15 -08:00
ken0nek
e7e70cea92 Add spaces before and after closure arrow in stdlib 2015-12-23 04:52:15 +09:00
Chris Lattner
e9a2e1e128 Eliminate all of the uses of ++/-- from stdlib/public/core.
At DaveA's suggestion, I took a mostly mechanical approach to this:
pointers and numeric types start using += 1, and indexes use
i = i.successor().  The index model is likely to be revised in
Swift 3 anyway, so micro-optimizing this code syntactically isn't
super important.

There is some performance concern of this patch, since some
in-place succesor operations are more efficient than
i = i.successor().  The one that seems particularly at issue is the
instance in the implementation of partition(), which I changed to
use i._successorInPlace().  If other instances lead to a perf issue,
they can be changed to use that as well.
2015-12-15 23:21:55 -08:00
Dmitri Gribenko
f25bf9eaf7 Merge pull request #544 from nielsandriesse/patch-11
Update _DropFirstSequence.next() for removal of ++ operator
2015-12-15 09:42:09 -08:00
Niels Andriesse
967ac96bb1 Update _PrefixSequence.next() for removal of ++ operator 2015-12-15 11:16:42 +11:00
Niels Andriesse
0e71b9277d Update _DropFirstSequence.next() for removal of ++ operator 2015-12-15 11:04:41 +11:00
Dmitri Gribenko
f431025638 stdlib: Fix documentation comments for Sequence.{dropFirst(),dropLast()} 2015-12-02 10:29:07 -08:00
Nadav Rotem
b6c284b24f Rename a variable. NFC.
"builder" -> "result", as requested by @gribozavr.
2015-12-01 17:10:42 -08:00
Nadav Rotem
2b47167d24 Simplify another implementation of map() and filter().
This commit removes _UnsafePartiallyInitializedContiguousArrayBuffer from two
more methods. I did not measure the performance impact of this change but I am
expecting this code to run faster.
2015-12-01 17:10:42 -08:00
Dmitri Hrybenko
6536edd68c stdlib: fix coding style
Swift SVN r32425
2015-10-03 21:13:15 +00:00
Dmitri Hrybenko
cf19c6c532 stdlib: format a code snippet as a code block
rdar://22422749

Swift SVN r31922
2015-09-14 06:29:25 +00:00
Dmitri Hrybenko
33631ca9c4 stdlib: Fix a bug in split()
split() used to drop the tail of the sequence under certain
circumstances.

rdar://22200821

Swift SVN r31207
2015-08-13 05:31:07 +00:00
Dmitri Hrybenko
4efa7f4372 stdlib: fix the docs to refer to the actual parameter name
Swift SVN r31205
2015-08-13 04:59:16 +00:00
Dmitri Hrybenko
255d2229c7 stdlib: remove erroneous @warn_unused_result annotations
Swift SVN r31050
2015-08-06 15:54:47 +00:00
Dmitri Hrybenko
dd3194a18c stdlib: adopt @warn_unused_result
rdar://20957486

Swift SVN r31048
2015-08-06 14:53:18 +00:00
Dmitri Hrybenko
827224f146 stdlib: clarify the behavior of sequences and for loops
This is not a new rule, this is just a consequence (although a
non-trivial one) of existing rules.

Swift SVN r31024
2015-08-05 19:06:10 +00:00
David Farler
311baf73cf Index protocol extensions
- Remove free Swift functions for advance and distance and replace
  them with protocol extension methods:
  - advancedBy(n)
  - advancedBy(n, limit:)
  - distanceTo(end)
- Modernize the Index tests
  - Use StdlibUnittest
  - Test for custom implementation dispatch

Perf impact: No significant changes reported in the
Swift Performance Measurement Tool.

rdar://problem/22085119

Swift SVN r30958
2015-08-03 20:06:44 +00:00
Dave Abrahams
ad43a596bd [stdlib] Retire the old lazy subsystem...
...replacing it with the new, after passing API review!

* The lazy free function has become a property.

* Before we could extend protocols, we lacked a means for value types to
  share implementations, and each new lazy algorithm had to be added to
  each of up to four types: LazySequence, LazyForwardCollection,
  LazyBidirectionalCollection, and LazyRandomAccessCollection. These
  generic adapters hid the usual algorithms by defining their own
  versions that returned new lazy generic adapters. Now users can extend
  just one of two protocols to do the same thing: LazySequenceType or
  LazyCollectionType.

* To avoid making the code duplication worse than it already was, the
  generic adapters mentioned above were used to add the lazy generic
  algorithms around simpler adapters such as MapSequence that just
  provided the basic requirements of SequenceType by applying a
  transformation to some base sequence, resulting in deeply nested
  generic types as shown here. Now, MapSequence is an instance of
  LazySequenceType (and is renamed LazyMapSequence), and thus transmits
  laziness to its algorithms automatically.

* Documentation comments have been rewritten.

* The .array property was retired

* various renamings

* A bunch of Gyb files were retired.

Swift SVN r30902
2015-08-01 03:52:13 +00:00
David Farler
7a49dda2c8 Add @warn_unused_result to map, flatMap, and filter
rdar://problem/21971932

Swift SVN r30849
2015-07-31 05:15:10 +00:00
Joe Groff
4cb34410fc stdlib: Don't reserve capacity for filter result array.
Swift SVN r30802
2015-07-30 17:07:37 +00:00
Joe Groff
0c39db22bc stdlib: Implement strict 'map', 'filter', and 'flatMap' as 'rethrows' operations.
Replace the Lazy-based implementations with open-coded implementations based on the _UnsafePartiallyInitializedContiguousArrayBuffer builder from the previous commit, so that we have control over the early-exit flow when an error interrupts the operation.

Swift SVN r30794
2015-07-30 05:28:34 +00:00
Joe Groff
f62d95dbc8 stdlib: Add 'rethrows' to more SequenceType and CollectionType algorithms.
Including:

- forEach
- split
- Optional flatMap
- minElement
- maxElement
- startsWith
- elementsEqual
- lexicographicalCompare
- contains
- reduce

Still not touching 'map', 'filter', 'flatMap', or 'sort', which need various levels of rearchitecting to fix.

Swift SVN r30792
2015-07-30 05:28:26 +00:00
Dave Abrahams
ea8c410509 [stdlib] Use new lazy collections in implementations
They pass various operations through to the base
collection (e.g. LazyMapCollection's .count) and thereby avoid taking
the potentially-slower path through the default implementation.

Swift SVN r30554
2015-07-23 21:02:45 +00:00
David Farler
9aa5ff1743 Clarify SequenceType.forEach's doc comment
- Add notes for the differences between forEach and for-in loops
- Use TSPL terminology

Swift SVN r30511
2015-07-22 22:56:14 +00:00
Dmitri Hrybenko
0525573de7 stdlib: use syntax sugar for Array
Swift SVN r30489
2015-07-22 04:16:22 +00:00
David Farler
ada08bdf2b SequenceType.split enhancements
- De-underscore the API that takes an equatable separator, add doc
  comment, and add a test for it.
- Add a test for the negative maxSplit case.
- Add lifetime tracker for isSeparator closure in the semantic test.

Swift SVN r30413
2015-07-20 21:34:19 +00:00
David Farler
deb69972a7 Clarify equivalence between SequenceType.forEach and for-in loops in doc comment
No functional change.

Swift SVN r30375
2015-07-18 09:08:13 +00:00
David Farler
e930494f35 Don't copy ring buffer in SequenceType.suffix
If the start of the ring buffer is aligned at the left, just wrap the
whole thing directly in an AnySequence and return it. Otherwise, return
a lazy concatenation of the the two slices of the ring buffer. This
prevents a forced full copy of the result.

rdar://problem/21885925

Swift SVN r30374
2015-07-18 09:04:56 +00:00
David Farler
0d1b03086d Add slicing extensions to SequenceType and CollectionType.
rdar://problem/21663830

Add the following new requirements to SequenceType with default implementations:

- dropFirst(n)
- dropLast(n)
- prefix(n)
- suffix(n)
- split(n)

In addition, provide specialized default implementations of these for CollectionTypes with forward, bidirectional, and random-access Index types where possible.

Add the following new requirements to CollectionType with default implementations:

- prefixThrough(n)
- prefixUpTo(n)
- suffixFrom(n)
- split() // isSeparator closure

Add the following convenience APIs:

- dropFirst() -> calls dropFirst(1)
- dropLast() -> calls dropLast(1)

Add a tentative underscored API:

- split() // takes Equatable separator.

Some APIs have undefined behavior when creating slices where the endpoints go beyond the bounds of the underlying collection. This will be fixed later by trapping creation of slices with invalid indices (rdar://problem/21822657).

Swift SVN r30371
2015-07-18 06:51:22 +00:00
David Farler
f1c5e503a9 Doc review: tweak SequenceType.forEach's doc comment
No functional change.

Swift SVN r30250
2015-07-16 04:28:43 +00:00
David Farler
86f1a7088b Review: Rename SequenceType.forEach parameter to 'body'
No functional change.

Swift SVN r30249
2015-07-16 04:07:17 +00:00
David Farler
91b89b8956 Add SequenceType.forEach requirement and default implementation
rdar://problem/21663830

Swift SVN r30236
2015-07-15 23:36:23 +00:00
Dave Abrahams
9d07acd368 [stdlib] SequenceType's _initializeTo should return the end position
Otherwise, the length of the sequence is in principle lost.  If you know
you have a sequence of less than 100 elements, you still want to know
exactly how many elements you initialized from it.

Swift SVN r30104
2015-07-11 01:43:27 +00:00
Dave Abrahams
ce8e51346c [stdlib] Remove a redundant and un-specific protocol extension
There's a better one in Sequence.swift; moving the comment there.

Swift SVN r30038
2015-07-09 20:27:19 +00:00
Dave Abrahams
913f09838a [stdlib] Add a default generate() for generators...
...that are also sequences, and rip out all redundant implementations of
generate() that match a default.

Swift SVN r30035
2015-07-09 19:49:24 +00:00
Dmitri Hrybenko
82122f9362 stdlib: fixit-based migrations for generic parameter renames
rdar://21538940

Swift SVN r29756
2015-06-27 04:06:27 +00:00
Dmitri Hrybenko
60ba7be3d1 stdlib: rename the generic parameter from T to Element on GeneratorSequence
Part of rdar://21429126

Swift SVN r29635
2015-06-24 20:42:02 +00:00
Greg Parker
6c812d0751 [stdlib] Reinstate r29043 "strip final from protocol extensions".
This reverts r29050. This wasn't the change that broke the SourceKit tests.


Swift SVN r29052
2015-05-27 01:52:17 +00:00
Greg Parker
16a3b8ebd7 [stdlib] Revert "strip final from protocol extensions".
SourceKit tests need to be updated.


Swift SVN r29050
2015-05-27 01:34:45 +00:00
Dave Abrahams
1f1643221d [stdlib] strip final from protocol extensions
Now that we've lifted the requirement

Swift SVN r29043
2015-05-26 23:52:36 +00:00
Dave Abrahams
fbfa056dc4 [stdlib] ~>_initializeTo(ptr) => method
Swift SVN r29002
2015-05-25 03:46:49 +00:00
Dave Abrahams
abf8e2f921 [stdlib] ~>_copyToNativeArrayBuffer() => method
Swift SVN r29001
2015-05-25 03:28:54 +00:00
Dave Abrahams
1bcd3ff761 [stdlib] Kill _Sequence_Type
Swift SVN r28972
2015-05-23 20:22:56 +00:00
Dave Abrahams
7f60c226be Kill _SequenceDefaultsType
Swift SVN r28898
2015-05-22 00:54:22 +00:00
Dmitri Hrybenko
55bb9a806b stdlib: replace implementations of unavailable functions with fatalError()
Reduces the stdandard library dylib size by 10 Kb for each slice.

Swift SVN r28884
2015-05-21 20:22:13 +00:00
Dmitri Hrybenko
53f3ccf850 stdlib: change CollectionType.count() into a property
Swift SVN r28829
2015-05-20 09:14:43 +00:00
Dmitri Hrybenko
313701286b stdlib: Various punctuation and markup improvements to the comments.
Patch by Brian Lanier.

Swift SVN r28659
2015-05-16 03:04:51 +00:00
Dmitri Hrybenko
25d9a4fe32 stdlib: protocol extensions: de-underscore filter()
The API was adjusted according to the API review previously.

Swift SVN r28592
2015-05-15 00:37:01 +00:00