From 912b88fd5706393b79af6b2d6a9d2ecf443e7c19 Mon Sep 17 00:00:00 2001 From: skidd13 Date: Fri, 19 Mar 2010 22:06:47 +0100 Subject: [PATCH 4/9] -Codechange: Move the basic code from CBlobT to ByteBlob and care just about type_size in CBlobT -Codechange: Add [] operator to CBlobT to get rid of Begin()[...] --- src/misc/blob.hpp | 20 +++++++++++++++++++- src/pathfinder/yapf/yapf_costrail.hpp | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/misc/blob.hpp b/src/misc/blob.hpp index 5065eb2..d5c88c4 100644 --- a/src/misc/blob.hpp +++ b/src/misc/blob.hpp @@ -181,6 +181,12 @@ public: return Hdr().capacity; }; + /** Return number of additional items that can fit in the Blob without buffer reallocation */ + FORCEINLINE uint Reserve() const + { + return Hdr().capacity - Hdr().items; + } + /** return pointer to the first byte of data - non-const version */ FORCEINLINE byte *Begin() { @@ -316,6 +322,18 @@ public: return (Begin() + index); } + /** Return reference to the index-th data item - non-const version */ + FORCEINLINE T &operator[](uint index) + { + return *Get(index); + } + + /** Return reference to the index-th data item - const version */ + FORCEINLINE const T &operator[](uint index) const + { + return *Get(index); + } + /** Return number of items in the Blob */ FORCEINLINE uint Length() const { @@ -331,7 +349,7 @@ public: /** Return number of additional items that can fit in the Blob without buffer reallocation */ FORCEINLINE uint Reserve() const { - return ((base::Capacity() - base::Length()) / type_size); + return base::Reserve() / type_size; } /** Grow number of data items in Blob by given number - doesn't construct items */ diff --git a/src/pathfinder/yapf/yapf_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp index b479095..ea3941b 100644 --- a/src/pathfinder/yapf/yapf_costrail.hpp +++ b/src/pathfinder/yapf/yapf_costrail.hpp @@ -200,7 +200,7 @@ public: n.m_last_signal_type = sig_type; /* cache the look-ahead polynomial constant only if we didn't pass more signals than the look-ahead limit is */ - int look_ahead_cost = (n.m_num_signals_passed < m_sig_look_ahead_costs.Length()) ? m_sig_look_ahead_costs.Begin()[n.m_num_signals_passed] : 0; + int look_ahead_cost = (n.m_num_signals_passed < m_sig_look_ahead_costs.Length()) ? m_sig_look_ahead_costs[n.m_num_signals_passed] : 0; if (sig_state != SIGNAL_STATE_RED) { /* green signal */ n.flags_u.flags_s.m_last_signal_was_red = false; -- 1.6.6.1