diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2018-04-25 22:40:24 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2018-04-26 22:53:33 +0300 |
commit | 2898c7ec9e5c76a6c6bba41c9d3f5a738cf2790a (patch) | |
tree | 357441206eebd2dd810524d18d242993c16ef79d | |
parent | 362151e8c8f2357d3c9dc4214f6e3e2a6aa51537 (diff) | |
download | mariadb-git-2898c7ec9e5c76a6c6bba41c9d3f5a738cf2790a.tar.gz |
MDEV-15914: Make mtr_buf_t a plain class
-rw-r--r-- | storage/innobase/include/dyn0buf.h | 61 |
1 files changed, 23 insertions, 38 deletions
diff --git a/storage/innobase/include/dyn0buf.h b/storage/innobase/include/dyn0buf.h index 3126c8e4683..4b6c808b47c 100644 --- a/storage/innobase/include/dyn0buf.h +++ b/storage/innobase/include/dyn0buf.h @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 2013, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2018, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -32,14 +33,13 @@ Created 2013-03-16 Sunny Bains #include "dyn0types.h" /** Class that manages dynamic buffers. It uses a UT_LIST of -dyn_buf_t::block_t instances. We don't use STL containers in +mtr_buf_t::block_t instances. We don't use STL containers in order to avoid the overhead of heap calls. Using a custom memory allocator doesn't solve the problem either because we have to get the memory from somewhere. We can't use the block_t::m_data as the backend for the custom allocator because we would like the data in the blocks to be contiguous. */ -template <size_t SIZE = DYN_ARRAY_DATA_SIZE> -class dyn_buf_t { +class mtr_buf_t { public: class block_t; @@ -47,17 +47,19 @@ public: typedef UT_LIST_NODE_T(block_t) block_node_t; typedef UT_LIST_BASE_NODE_T(block_t) block_list_t; + /** SIZE - sizeof(m_node) + sizeof(m_used) */ + enum { MAX_DATA_SIZE = DYN_ARRAY_DATA_SIZE + - sizeof(block_node_t) + sizeof(ib_uint32_t) }; + class block_t { public: block_t() { - ut_ad(MAX_DATA_SIZE <= (2 << 15)); + compile_time_assert(MAX_DATA_SIZE <= (2 << 15)); init(); } - ~block_t() { } - /** Gets the number of used bytes in a block. @return number of bytes used */ @@ -112,12 +114,12 @@ public: /** @return pointer to start of reserved space */ template <typename Type> - Type push(ib_uint32_t size) + Type push(uint32_t size) { Type ptr = reinterpret_cast<Type>(end()); m_used += size; - ut_ad(m_used <= static_cast<ib_uint32_t>(MAX_DATA_SIZE)); + ut_ad(m_used <= uint32_t(MAX_DATA_SIZE)); return(ptr); } @@ -131,7 +133,7 @@ public: ut_ad(ptr <= begin() + m_buf_end); /* We have done the boundary check above */ - m_used = static_cast<ib_uint32_t>(ptr - begin()); + m_used = uint32_t(ptr - begin()); ut_ad(m_used <= MAX_DATA_SIZE); ut_d(m_buf_end = 0); @@ -154,13 +156,6 @@ public: ulint m_magic_n; #endif /* UNIV_DEBUG */ - /** SIZE - sizeof(m_node) + sizeof(m_used) */ - enum { - MAX_DATA_SIZE = SIZE - - sizeof(block_node_t) - + sizeof(ib_uint32_t) - }; - /** Storage */ byte m_data[MAX_DATA_SIZE]; @@ -169,15 +164,13 @@ public: /** number of data bytes used in this block; DYN_BLOCK_FULL_FLAG is set when the block becomes full */ - ib_uint32_t m_used; + uint32_t m_used; - friend class dyn_buf_t; + friend class mtr_buf_t; }; - enum { MAX_DATA_SIZE = block_t::MAX_DATA_SIZE}; - /** Default constructor */ - dyn_buf_t() + mtr_buf_t() : m_heap(), m_size() @@ -187,7 +180,7 @@ public: } /** Destructor */ - ~dyn_buf_t() + ~mtr_buf_t() { erase(); } @@ -252,7 +245,7 @@ public: @param size in bytes of the element @return pointer to the element */ template <typename Type> - Type push(ib_uint32_t size) + Type push(uint32_t size) { ut_ad(size > 0); ut_ad(size <= MAX_DATA_SIZE); @@ -272,17 +265,11 @@ public: Pushes n bytes. @param str string to write @param len string length */ - void push(const byte* ptr, ib_uint32_t len) + void push(const byte* ptr, uint32_t len) { while (len > 0) { - ib_uint32_t n_copied; - - if (len >= MAX_DATA_SIZE) { - n_copied = MAX_DATA_SIZE; - } else { - n_copied = len; - } - + uint32_t n_copied = std::min(len, + uint32_t(MAX_DATA_SIZE)); ::memmove(push<byte*>(n_copied), ptr, n_copied); ptr += n_copied; @@ -298,7 +285,7 @@ public: const Type at(ulint pos) const { block_t* block = const_cast<block_t*>( - const_cast<dyn_buf_t*>(this)->find(pos)); + const_cast<mtr_buf_t*>(this)->find(pos)); return(reinterpret_cast<Type>(block->begin() + pos)); } @@ -391,8 +378,8 @@ public: private: // Disable copying - dyn_buf_t(const dyn_buf_t&); - dyn_buf_t& operator=(const dyn_buf_t&); + mtr_buf_t(const mtr_buf_t&); + mtr_buf_t& operator=(const mtr_buf_t&); /** Add the block to the end of the list*/ @@ -404,7 +391,7 @@ private: } /** @return the last block in the list */ - block_t* back() + block_t* back() const { return(UT_LIST_GET_LAST(m_list)); } @@ -484,8 +471,6 @@ private: block_t m_first_block; }; -typedef dyn_buf_t<DYN_ARRAY_DATA_SIZE> mtr_buf_t; - /** mtr_buf_t copier */ struct mtr_buf_copy_t { /** The copied buffer */ |