Commit Graph

48 Commits

Author SHA1 Message Date
Dmitri Hrybenko
397d2fb8c3 stdlib: coding style: when colon specifies is-a relationship, we put
spaces on both sides of it

Swift SVN r23935
2014-12-15 06:55:30 +00:00
Dave Abrahams
73956eb509 [stdlib] Better predicate docs/name for lexicographicalCompare
Swift SVN r23006
2014-10-29 19:00:08 +00:00
Dave Abrahams
156020de19 [stdlib] Rename 'countElements' => 'count'
The name was not only long and unwieldy, but inconsistent with our
conscious decision to avoid the use of "elements" in APIs as mostly
redundant.

Swift SVN r22408
2014-09-30 22:00:26 +00:00
Dave Abrahams
824e78dd89 [stdlib] pick off public non-protocol docs
197 undocumented public non-operator APIs remain in core

Swift SVN r22242
2014-09-23 23:36:00 +00:00
Dave Abrahams
f4a7812065 [stdlib] Propagate SequenceType docs to models
235 undocumented public APIs remain in core

Swift SVN r22210
2014-09-23 10:40:37 +00:00
Dave Abrahams
76f9313088 [stdlib] Propagate GeneratorType docs to models
Swift SVN r22208
2014-09-23 09:47:26 +00:00
Dave Abrahams
214c7bc0fd [stdlib] Correct some ReST markup
Swift SVN r22037
2014-09-17 20:44:07 +00:00
Dave Abrahams
8ec2b299f3 [stdlib] Algorithm.swift: doc-comment public API
Swift SVN r21890
2014-09-11 20:20:19 +00:00
Dave Abrahams
107dca088c [stdlib] Separate Sequence type for enumerate
Avoids surprise in case someone makes a generator with reference
semantics

Swift SVN r21886
2014-09-11 19:57:20 +00:00
Dave Abrahams
1e9e7734f0 Revert "[stdlib] any/all algorithms, keyword for contains"
This reverts r21810 and r21811 due to lack of design consensus

Swift SVN r21880
2014-09-11 17:42:32 +00:00
Dave Abrahams
c467825bc2 [stdlib] any/all algorithms, keyword for contains
Expose any, all on Array and all the Lazy sequence adapters.  Make the
'contains' algorithm that takes a predecate unavailable in favor of
'any', which does the same thing.

Fixes <rdar://problem/18190149> [algorithm] `contains` syntax is ambiguous

Swift SVN r21810
2014-09-09 20:39:39 +00:00
Mikhail Zolotukhin
4027d140d1 stdlib: Replace quicksort with introsort.
Also, unite predicated and unpredicated versions of all functions via
GYB.

Swift SVN r21280
2014-08-19 13:41:04 +00:00
Dave Abrahams
35d9fc22fa [stdlib] Doc comment reduce algorithm
Swift SVN r21206
2014-08-14 17:36:49 +00:00
Dave Abrahams
1eba71e4e6 [stdlib] Doc comments and parameter naming, NFC
Fixes <rdar://problem/17998481>

Swift SVN r21204
2014-08-14 17:31:54 +00:00
Joe Pamer
96a5df8281 Remove one more optional-as-boolean.
Swift SVN r20640
2014-07-28 19:20:42 +00:00
Joe Pamer
94dac129d4 Remove the BooleanType conformance from optional types (rdar://problem/17110911)
To limit user confusion when using conditional expressions of type Bool?, we've decided to remove the BooleanType (aka "LogicValue") conformance from optional types. (If users would like to use an expression of type Bool? as a conditional, they'll need to check against nil.)

Note: This change effectively regresses the "case is" pattern over types, since it currently demands a BooleanType conformance. I've filed rdar://problem/17791533 to track reinstating it if necessary.

Swift SVN r20637
2014-07-28 19:20:39 +00:00
Dmitri Hrybenko
a4c1ef90e7 stdlib/Algorithm: add an overload for startsWith that accepts a
comparison predicate

Swift SVN r20601
2014-07-27 01:00:26 +00:00
Dave Abrahams
e3f8d0e630 [stdlib] rename UnsafeArray => UnsafeBufferPointer
Also,

  UnsafeMutableArray => UnsafeMutableBufferPointer
  withUnsafeMutableStorage => withUnsafeMutableBufferPointer

Swift SVN r20340
2014-07-22 22:20:37 +00:00
Dmitri Hrybenko
d14f17beef Change 'getLogicValue()' into a property 'boolValue'; change
'getArrayBoundValue()' into a property 'arrayBoundValue'.

rdar://17156123


Swift SVN r20304
2014-07-22 12:08:10 +00:00
Dave Abrahams
de368b9070 [stdlib] Make algorithms safe with illegal predicates
Even if the user supplies an ordering predicate that isn't a strict-weak
ordering, algorithms should not index beyond their bounds.  Otherwise, a
use of withUnsafeMutableStorage for optimization purposes could easily
do an unsafe memory access.

This commit comments and tests our algorithms that require strict weak
orderings, and fixes safety problems in partition().  Most benchmarks
are unaffected, but the rewrite of partition produces a 27% speedup in
the Phonebook benchmark at -O3 and a 22% speedup at -Ofast.

Also, at -Ofast, QuickSort lost 6% and RC4 gained 6%.  These benchmarks
were not noticeably affected at -O3

====================`PrecommitBench_O3`====================
````benchmark`,`baserun0`,`baserun1`,`baserun2`,``optrun0`,``optrun1`,``optrun2`,``delta`,`speedup`
````Phonebook`,``1608.00`,``1676.00`,``1651.00`,``1265.00`,``1278.00`,``1281.00`,`343.00`,```27.1%`
````QuickSort`,```430.00`,```448.00`,```429.00`,```428.00`,```431.00`,```428.00`,```1.00`,````0.2%`
``````````RC4`,```925.00`,```924.00`,```922.00`,```916.00`,```919.00`,```917.00`,```6.00`,````0.7%`
====================`PrecommitBench_Ofast`====================
````benchmark`,`baserun0`,`baserun1`,`baserun2`,``optrun0`,``optrun1`,``optrun2`,``delta`,`speedup`
````Phonebook`,``1521.00`,``1546.00`,``1591.00`,``1252.00`,``1255.00`,``1256.00`,`269.00`,```21.5%`
````QuickSort`,```478.00`,```477.00`,```476.00`,```506.00`,```510.00`,```513.00`,``30.00`,```-5.9%`
``````````RC4`,``1033.00`,``1874.00`,``1030.00`,```974.00`,```982.00`,```975.00`,``56.00`,````5.7%`

Swift SVN r20202
2014-07-19 01:51:03 +00:00
Dave Abrahams
6bbbf052a3 [stdlib] _partition doesn't need to be public!
Thanks, Jordan

Swift SVN r20194
2014-07-19 00:38:48 +00:00
Dave Abrahams
ec8b29cdf1 [stdlib] Fix the public interface of partition
It should not take the predicate as inout!

Swift SVN r20193
2014-07-19 00:35:45 +00:00
Dave Abrahams
0412b0cfc1 [stdlib] BooleanType is just for Bools
For now, it still applies to Optionals and Pointers, but this commit
removes it from everything else.

Swift SVN r19888
2014-07-13 01:19:39 +00:00
Dave Abrahams
cbcf9aba21 s/LogicValueType/BooleanType/
We're moving toward using that protocol for straight-up Bool types

Swift SVN r19884
2014-07-12 18:58:18 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Dmitri Hrybenko
12aaf7543b stdlib: remove 'public' from private functions
Swift SVN r19686
2014-07-08 16:47:10 +00:00
Dmitri Hrybenko
977d901643 stdlib: hide quickSort and insertionSort
Finishes rdar://17315534


Swift SVN r19682
2014-07-08 10:33:23 +00:00
Dmitri Hrybenko
8fb09ef13a stdlib: update comments and parameter names for startsWith() algorithm to
clearly reflect semantics

rdar://17567069


Swift SVN r19681
2014-07-08 09:54:10 +00:00
Jordan Rose
da29f099f0 Update stdlib for accessibility modifiers becoming context-sensitive keywords.
Swift SVN r19672
2014-07-08 02:17:46 +00:00
Dave Abrahams
9825954746 [stdlib] That's not a doc comment!
Fixes <rdar://problem/17028678> comments for sort() don't make sense in
the synthesized header.  Putting the right comments in there is
<rdar://problem/17511801> Algorithm.swift needs doc comments

Swift SVN r19370
2014-06-30 21:46:19 +00:00
Dave Abrahams
c1539b3e5d [stdlib] Put the "unsafe" in withUnsafeMutableStorage
This API exposes unmediated access to memory, and most users will never
see the UnsafeArray argument that's passed to the closure, so best to be
explicit.

Swift SVN r19243
2014-06-26 18:22:54 +00:00
Doug Gregor
37df5c430c Update standard library to use [T] array syntax.
Swift SVN r19190
2014-06-25 23:39:20 +00:00
Ted Kremenek
0ce574eb9e Correct mistake where some 'pred' arguments became 'predecessor' instead of 'predicate'.
Thanks to Dmitri and Joe for pointing this out.

Swift SVN r19151
2014-06-24 23:47:00 +00:00
Jordan Rose
cca27d02a0 Tag everything in the standard library with accessibility attributes.
Keep calm: remember that the standard library has many more public exports
than the average target, and that this contains ALL of them at once.
I also deliberately tried to tag nearly every top-level decl, even if that
was just to explicitly mark things @internal, to make sure I didn't miss
something.

This does export more than we might want to, mostly for protocol conformance
reasons, along with our simple-but-limiting typealias rule. I tried to also
mark things private where possible, but it's really going to be up to the
standard library owners to get this right. This is also only validated
against top-level access control; I haven't fully tested against member-level
access control yet, and none of our semantic restrictions are in place.

Along the way I also noticed bits of stdlib cruft; to keep this patch
understandable, I didn't change any of them.

Swift SVN r19145
2014-06-24 21:32:18 +00:00
Ted Kremenek
58558fcca3 Rename 'succ' and 'pred' to 'successor' and 'predecessor' respectively.
This is motivated by <rdar://problem/17051606>.

This ends up renaming variables as well, which seems right for
consistency since we use "predicate" as variable name.

Swift SVN r19135
2014-06-24 19:27:19 +00:00
Chris Lattner
62cad3dce8 add a "..<" operator, which is an alias for ".." and switch the stdlib to use it.
Until I have a chance to update the testsuite, we'll accept both.



Swift SVN r18998
2014-06-19 05:42:29 +00:00
Dave Abrahams
c5c17e2615 [stdlib] Sort Arrays using bulk mutation backdoor
This results in a a massive speedup and could in principle be applied to
other bulk array mutations.

Swift SVN r18926
2014-06-16 14:04:54 +00:00
Dave Abrahams
acc2c3be40 [stdlib] Prepare array sort for value semantics
Sorting was a bit of a mess; we had sort functions doing in-place
mutation /and/ returing the value, and people were confused by the
asymmetry of Array's sort() method with other higher-level methods.

Fixes <rdar://problem/17185815> sort([]T, f) mutates the original array
<rdar://problem/17225190> The Array.sort() method should return a sorted array

Swift SVN r18922
2014-06-16 13:48:43 +00:00
Manman Ren
e3517e8792 [stdlib] add two-operand version of min.
This corresponds to the change on max at r18767.


Swift SVN r18769
2014-06-10 00:57:08 +00:00
Manman Ren
4c284e48bd [stdlib] add two-operand version of max.
This helps array append's performance by ~ 2x. The generic max with a variadic
argument takes at least 3 arguments, it creates a temporary array then iterates
over the array.

This is an updated version of r18764.
rdar://17140639 rdar://17073827


Swift SVN r18767
2014-06-10 00:33:46 +00:00
Manman Ren
aec78d0693 [stdlib] revert r18764.
Swift SVN r18765
2014-06-10 00:13:41 +00:00
Manman Ren
cc90c81239 [stdlib] add two-operand version of max and use max2 in stdlib when appropriate.
This helps array append's performance by ~ 2x. The generic max with a variadic
argument creates a temporary array then iterates over the array.

rdar://17140639 rdar://17073827


Swift SVN r18764
2014-06-09 23:56:40 +00:00
Nadav Rotem
04b17cc63f Add comments. NFC.
Swift SVN r18637
2014-05-26 19:52:01 +00:00
Nadav Rotem
1c3c12fd5e Fix a bug in the partition() method that is used by sort.
The problem was that we were swapping the pivot while partitioning the array.

Thanks Dave!



Swift SVN r18611
2014-05-24 01:24:34 +00:00
Dmitri Hrybenko
a4d9dcf1a7 stdlib: extinguish \brief and \c
Swift SVN r18261
2014-05-17 18:10:51 +00:00
Ted Kremenek
9eea282719 Switch range operators ".." and "...".
- 1..3 now means 1,2
- 1...3 now means 1,2,3

Implements <rdar://problem/16839891>

Swift SVN r18066
2014-05-14 07:36:00 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Dmitri Hrybenko
29cebdf797 Splitting the standard library: step 1: move stdlib -> stdlib/core
Swift SVN r5864
2013-06-28 02:31:01 +00:00