orlandos-nl / BSON

Native Swift library for BSON (http://bsonspec.org)
https://orlandos.nl/docs/mongokitten/articles/bson
MIT License
108 stars 36 forks source link

Fix latest swift 4.2 snapshot compile error on linux. #49

Closed Andrewangeta closed 6 years ago

Andrewangeta commented 6 years ago

@Obbut @Joannis Can you take a look when you get a chance. Fixes this compile issue.

screen shot 2018-07-24 at 9 16 20 pm
Joannis commented 6 years ago

Thanks for the attempt 👍 The reason I didn't accept it is because your solution makes a lot of copies.

If you initialize arrays from a sequence you're using the protocol's makeIterator() and iterating over that iterator. This copies every byte one-by-one to the array (expanding the array many times). This results in a large performance loss since you're not copying the data in bulk. So the alternative code I posted (which was the intended version) expands the data once, and then copies the BufferPointer's data to there once which is really cheap.

Thanks for the help regardless! Hope the above helps you learn more about this!

Andrewangeta commented 6 years ago

No problem! Thanks for the explanation, we all want better performance.