aboutsummaryrefslogtreecommitdiff
path: root/src/prevector.h
AgeCommit message (Collapse)Author
2019-12-30scripted-diff: Bump copyright of files changed in 2019MarcoFalke
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT-
2019-11-29Use correct C++11 header for std::swap()Hennadii Stepanov
2019-10-15Remove unused includespracticalswift
2019-06-18Merge #12324: speed up Unserialize_impl for prevectorWladimir J. van der Laan
86b47fa741408b061ab0bda784b8678bfd7dfa88 speed up Unserialize_impl for prevector (Akio Nakamura) Pull request description: The unserializer for prevector uses `resize()` for reserve the area, but it's prefer to use `reserve()` because `resize()` have overhead to call its constructor many times. However, `reserve()` does not change the value of `_size` (a private member of prevector). This PR make the logic of read from stream to callback function, and prevector handles initilizing new values with that call-back and ajust the value of `_size`. The changes are as follows: 1. prevector.h Add a public member function named 'append'. This function has 2 params, number of elemenst to append and call-back function that initilizing new appended values. 2. serialize.h In the following two function: - `Unserialize_impl(Stream& is, prevector<N, T>& v, const unsigned char&)` - `Unserialize_impl(Stream& is, prevector<N, T>& v, const V&)` Make a callback function from each original logic of reading values from stream, and call prevector's `append()`. 3. test/prevector_tests.cpp Add a test for `append()`. ## A benchmark result is following: [Machine] MacBook Pro (macOS 10.13.3/i7 2.2GHz/mem 16GB/SSD) [result] DeserializeAndCheckBlockTest => 22% faster DeserializeBlockTest => 29% faster [before PR] # Benchmark, evals, iterations, total, min, max, median DeserializeAndCheckBlockTest, 60, 160, 94.4901, 0.0094644, 0.0104715, 0.0098339 DeserializeBlockTest, 60, 130, 65.0964, 0.00800362, 0.00895134, 0.00824187 [After PR] # Benchmark, evals, iterations, total, min, max, median DeserializeAndCheckBlockTest, 60, 160, 77.1597, 0.00767013, 0.00858959, 0.00805757 DeserializeBlockTest, 60, 130, 49.9443, 0.00613926, 0.00691187, 0.00635527 ACKs for top commit: laanwj: utACK 86b47fa741408b061ab0bda784b8678bfd7dfa88 Tree-SHA512: 62ea121ccd45a306fefc67485a1b03a853435af762607dae2426a87b15a3033d802c8556e1923727ddd1023a1837d0e5f6720c2c77b38196907e750e15fbb902
2019-05-06Merge #14266: refactor: Lift prevector default vals to the member declarationMarcoFalke
d2eee87928 Lift prevector default vals to the member declaration (Ben Woosley) Pull request description: I overlooked this possibility in #14028 ACKs for commit d2eee8: promag: utACK d2eee87, change looks good because members are always initialized. 251Labs: utACK d2eee87 nice one. ken2812221: utACK d2eee87928781ab3082d4279aa6f19641a45e801 practicalswift: utACK d2eee87928781ab3082d4279aa6f19641a45e801 scravy: utACK d2eee87928781ab3082d4279aa6f19641a45e801 Tree-SHA512: f2726bae1cf892fd680cf8571027bcdc2e42ba567eaa901fb5fb5423b4d11b29e745e0163d82cb513d8c81399cc85933a16ed66d4a30829382d4721ffc41dc97
2019-02-03speed up Unserialize_impl for prevectorAkio Nakamura
The unserializer for prevector uses resize() for reserve the area, but it's prefer to use reserve() because resize() have overhead to call its constructor many times. However, reserve() does not change the value of "_size" (a private member of prevector). This PR introduce resize_uninitialized() to prevector that similar to resize() but does not call constructor, and added elements are explicitly initialized in Unserialize_imple(). The changes are as follows: 1. prevector.h Add a public member function named 'resize_uninitialized'. This function processes like as resize() but does not call constructors. So added elemensts needs explicitly initialized after this returns. 2. serialize.h In the following two function: Unserialize_impl(Stream& is, prevector<N, T>& v, const unsigned char&) Unserialize_impl(Stream& is, prevector<N, T>& v, const V&) Calls resize_uninitialized() instead of resize() 3. test/prevector_tests.cpp Add a test for resize_uninitialized().
2018-11-14Implement prevector::fill onceBen Woosley
Now that the implementation is identical, we can use a default value to distinguish them.
2018-11-14Drop defunct IS_TRIVIALLY_CONSTRUCTIBLE handling from prevector.hBen Woosley
It's now only referenced from the bench, so leave it there. This allows us to drop the associated includes as well.
2018-11-04warnings: Compiler warning on memset usage for non-trivial typeLenny Maiorani
Problem: - IS_TRIVIALLY_CONSTRUCTIBLE macro does not work correctly resulting in `memset()` usage to set a non-trivial type to 0 when `nontrivial_t` is passed in from the tests. - Warning reported by GCC when compiling with `--enable-werror`. Solution: - Use the standard algorithm `std::fill_n()` and let the compiler determine the optimal way of looping or using `memset()`.
2018-09-19Lift prevector default vals to the member declarationBen Woosley
2018-08-27Explicitly initialize prevector _unionBen Woosley
2018-08-23Remove default argument to prevector constructor to remove ambiguityBen Woosley
The call with this default argument is redundant with prevector(size_type).
2018-07-27Update copyright headers to 2018DrahtBot
2018-02-27Use memset() to optimize prevector::resize()Evan Klitzke
Further optimize prevector::resize() (which is called by a number of other prevector methods) to use memset to initialize memory when the prevector contains trivial types.
2018-02-27Reduce redundant code of prevector and speed it upAkio Nakamura
In prevector.h, the code which like item_ptr(size()) apears in the loop. Both item_ptr() and size() judge whether values are held directly or indirectly, but in most cases it is sufficient to make that judgement once outside the loop. This PR adds 2 private function fill() which has the loop to initialize by specified value (or iterator of the other prevector's element), but don't call item_ptr() in their loop. Other functions(assign(), constructor, operator=(), insert()) that has similar loop, call fill() instead of original loop. Also, resize() was changed like fill(), but it calls the default constructor for that element each time.
2018-01-03Increment MIT Licence copyright header year on files modified in 2017Akira Takizawa
2017-08-26Fix header guards using reserved identifiersDan Raviv
Identifiers beginning with an underscore followed immediately by an uppercase letter are reserved.
2017-08-07scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal ↵practicalswift
instead of the macro NULL -BEGIN VERIFY SCRIPT- sed -i 's/\<NULL\>/nullptr/g' src/*.cpp src/*.h src/*/*.cpp src/*/*.h src/qt/*/*.cpp src/qt/*/*.h src/wallet/*/*.cpp src/wallet/*/*.h src/support/allocators/*.h sed -i 's/Prefer nullptr, otherwise SAFECOOKIE./Prefer NULL, otherwise SAFECOOKIE./g' src/torcontrol.cpp sed -i 's/tor: Using nullptr authentication/tor: Using NULL authentication/g' src/torcontrol.cpp sed -i 's/METHODS=nullptr/METHODS=NULL/g' src/test/torcontrol_tests.cpp src/torcontrol.cpp sed -i 's/nullptr certificates/NULL certificates/g' src/qt/paymentserver.cpp sed -i 's/"nullptr"/"NULL"/g' src/torcontrol.cpp src/test/torcontrol_tests.cpp -END VERIFY SCRIPT-
2017-07-14Explicitly initialize prevector::_union to avoid new warningMatt Corallo
Warning from gcc 7.1 is ./prevector.h:450:25: warning: '*((void*)(&<anonymous>)+8).prevector<28, unsigned char>::_union.prevector<28, unsigned char>::direct_or_indirect::<anonymous>.prevector<28, unsigned char>::direct_or_indirect::<unnamed struct>::indirect' may be used uninitialized in this function [-Wmaybe-uninitialized]
2017-06-22Fix const_reverse_iterator constructor (pass const ptr)Jorge Timón
2017-06-09Clarify prevector::erase and avoid swap-to-clearPieter Wuille
2017-03-14Merge #9505: Prevector Quick DestructWladimir J. van der Laan
45a5aaf Only call clear on prevector if it isn't trivially destructible and don't loop in clear (Jeremy Rubin) aaa02e7 Add prevector destructor benchmark (Jeremy Rubin) Tree-SHA512: 52bc8163b65b71310252f2d578349d0ddc364a6c23795c5e06e101f5449f04c96cbdca41c0cffb1974b984b8e33006471137d92b8dd4a81a98e922610a94132a
2017-02-27prevector: assert successful allocationCory Fields
2017-01-10Only call clear on prevector if it isn't trivially destructible and don't ↵Jeremy Rubin
loop in clear
2016-12-31Increment MIT Licence copyright header year on files modified in 2016isle2983
Edited via: $ contrib/devtools/copyright_header.py update .
2016-12-21Make CScript (and prevector) c++11 movable.Pieter Wuille
Such moves are used when reallocating vectors that contain them, for example.
2016-10-02serialize: Deprecate `begin_ptr` / `end_ptr`Wladimir J. van der Laan
Implement `begin_ptr` and `end_ptr` in terms of C++11 code, and add a comment that they are deprecated. Follow-up to developer notes update in 654a21162252294b7dbd6c982fec88008af7335e.
2016-09-30prevector: add C++11-like data() methodWladimir J. van der Laan
This returns a pointer to the beginning of the vector's data.
2016-04-16prevector::swap: fix (unreached) data corruptionKaz Wesley
swap was using an incorrect condition to determine when to apply an optimization (not swapping the full direct[] when swapping two indirect prevectors). Rather than correct the optimization I'm removing it for simplicity. Removing this optimization minutely improves performance in the typical (currently only) usage of member swap(), which is swapping with a freshly value-initialized object.
2016-04-16prevector: destroy elements only via erase()Kaz Wesley
Fixes a bug in which pop_back did not call the deleted item's destructor. Using the most general erase() implementation to implement all the others prevents similar bugs because the coupling between deallocation and destructor invocation only needs to be maintained in one place. Also reduces duplication of complex memmove logic.
2016-01-05Add missing copyright headersMarcoFalke
2015-12-02Name union to prevent compiler warningPavel Janík
2015-11-13Prevector typePieter Wuille