> On 12 Oct 2016, at 23:05, Joe Groff via swift-users
> wrote:
>
>>
>> On Oct 12, 2016, at 2:25 AM, Gerriet M. Denkmann via swift-users
>> wrote:
>>
>> uint64_t nbrBytes = 4e8;
>> uint64_t count = 0;
>> for( uint64_t byteIndex = 0; byteIndex <
> On Oct 12, 2016, at 3:21 AM, Jean-Denis Muys via swift-users
> wrote:
>
>
> But this is not very DRY.
>
> What would be a more idiomatic way?
>
The more idiomatic way is to look at API design in a new way. Note these points:
1. `Countable` variant is preferred
Greetings,
I'm not sure where to take this issue, so I'm starting here. It's an
installation issue, not a language issue. Any tips on where to send this
would be greatly appreciated! (And of course please let me know if it's a
known issue.)
I'm one of the brave that is installing Swift 3.0 on
Not in this case, today:
--
$ cat x.swift
import Darwin.C
public class AtomicInt32 {
public fileprivate (set) var value : Int32 = 0
/// Create a new atomic integer with the specified initial value.
public init(_ value: Int32 = 0) {
self.value = value
}
/// Add one to the
Yes, it is so inconvenient to use that CloseRange isn’t the special of Range.
But according to your case, CountableRange can be used in the condition. And
ClosedCountableRange and CountableRange is available to converting. Refer:
https://oleb.net/blog/2016/09/swift-3-ranges/
Or allocate a pointer for it. The other alternative would be NSLock but that
might be swatting flies with sledgehammers. We had a similar issue implementing
NSLock in swift-corelibs-foundation where taking the address of a pthread mutex
corrupted the structure for when another thread would
You could also create a “Range” protocol with “lowerBound” and “upperBound”
properties. Conform all the range types to it, and make your function take
generic over the protocol.
Nevin
On Wed, Oct 12, 2016 at 7:21 PM, Hooman Mehr via swift-users <
swift-users@swift.org> wrote:
> I recommend
So we would have to drop down to C code, etc. to safely leverage OSAtomic?
On Wed, Oct 12, 2016 at 8:32 AM Philippe Hausler via swift-users <
swift-users@swift.org> wrote:
> I was under the impression that taking the address was more than a single
> load instruction and would emit a placeholder
I recommend having explicit precondition and reducing repetition like this:
import Foundation
func random(from range: CountableRange) -> Int {
precondition(range.count > 0,
"The range can't be empty.")
return random(from: CountableClosedRange(range))
}
func
> On Oct 12, 2016, at 2:25 AM, Gerriet M. Denkmann via swift-users
> wrote:
>
> uint64_t nbrBytes = 4e8;
> uint64_t count = 0;
> for( uint64_t byteIndex = 0; byteIndex < nbrBytes; byteIndex++ )
> {
> count += byteIndex;
> if ( ( byteIndex & 0x ) == 0
Dash + Alfred :)
> On 12 Oct 2016, at 17:13, Lars-Jørgen Kristiansen via swift-users
> wrote:
>
> I recommend Dash
>
>> 12. okt. 2016 kl. 17.03 skrev Adrian Zubarev via swift-users
>> >:
>>
>> You could also
I suspect one of the actual compiler people might tell me I shouldn't trust
this, but in practice it works:
--
import Darwin.C
public class AtomicInt32 {
public fileprivate (set) var value : Int32 = 0
/// Create a new atomic integer with the specified initial value.
public
You could also fallback to http://swiftdoc.org. ;)
--
Adrian Zubarev
Sent with Airmail
Am 12. Oktober 2016 um 17:01:48, Jon Shier via swift-users
(swift-users@swift.org) schrieb:
I’m guessing you only came to Apple’s developer environment with Swift? (If not
I apologize.) The searchability
I’ve been bitten by that quite a few times. I’m not a fan of the new
distinction between Range and ClosedRange. I understand the reasoning behind
them, but the new model is creating more problems for me than the it solves.
David.
> On 12 Oct 2016, at 12:21, Jean-Denis Muys via swift-users
>
Hi,
I defined this:
func random(from r: Range) -> Int {
let from = r.lowerBound
let to = r.upperBound
let rnd = arc4random_uniform(UInt32(to-from))
return from + Int(rnd)
}
so that I can do:
let testRandomValue = random(from: 4..<8)
But this will not let me do:
let
Is it just me, or is the Standard library document not very discoverable?
Try searching developer.apple.com for "(Swift) standard library". No hit!
Can’t find it on swift.org either (which isn’t even searchable).
In case anybody else needs it, Mateusz Malczak gave me the link:
uint64_t nbrBytes = 4e8;
uint64_t count = 0;
for( uint64_t byteIndex = 0; byteIndex < nbrBytes; byteIndex++ )
{
count += byteIndex;
if ( ( byteIndex & 0x ) == 0 ) { count += 1.3; } (AAA)
};
Takes 260 msec.
Btw.: Without the (AAA) line the whole loop is done in 10 μsec.
How to translate this to Swift:
__block atomic_uint_fast64_t counter = ATOMIC_VAR_INIT(0);
dispatch_apply( nbrInterations, queue, ^void(size_t idx)
{
uint64_t tCount = 0;
... do some counting ...
atomic_fetch_add_explicit( , tCount,
With:
let nbrBytes = 400_000_000
let localArray = UnsafeMutablePointer.allocate(capacity: nbrBytes)
// touch every page before summing:
for i in 0 ..< nbrBytes / 4096 { localArray[ 4096 * i ] = 1 }
This rather innocent loop:
var count: UInt64 = 0
for index in 0 ..< loopLimit { count +=
19 matches
Mail list logo