From 1c251699c35f718803c6bed209e7417939edae99 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 30 Jul 2012 16:32:32 +1000 Subject: [PATCH] Use an array not a vector for components --- version.cpp.rl | 25 +++++++++++++------------ version.hpp | 24 +++++++++++------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/version.cpp.rl b/version.cpp.rl index 9819a1af..9f84d68c 100644 --- a/version.cpp.rl +++ b/version.cpp.rl @@ -32,25 +32,26 @@ using namespace util; version::version (unsigned int _major, unsigned int _minor): - m_values (2), - m_release (RELEASE_PRODUCTION) { + m_size (2), + m_release (RELEASE_PRODUCTION) +{ m_values[OFFSET_MAJOR] = _major; m_values[OFFSET_MINOR] = _minor; } version::version (const string& str): - m_values (NUM_OFFSETS, 0), - m_release (RELEASE_PRODUCTION) { - m_values.clear (); + m_size (0), + m_release (RELEASE_PRODUCTION) +{ parse (str); } version::version (const char *str): - m_values (NUM_OFFSETS, 0), - m_release (RELEASE_PRODUCTION) { - m_values.clear (); + m_size (0), + m_release (RELEASE_PRODUCTION) +{ parse (str); } @@ -72,7 +73,7 @@ check_release (version::release_t r) { void version::sanity (void) const { check_release (m_release); - CHECK (!m_values.empty ()); + CHECK (m_size > 0); } @@ -85,7 +86,7 @@ version::sanity (void) const { { current *= 10; current += (uintptr_t)(fc - (unsigned char)'0'); } action finish - { m_values.push_back (current); } + { m_values[m_size++] = current; } number = (digit+) >clear @@ -101,7 +102,7 @@ version::sanity (void) const { version := (dots type?) $!{ throw invalid_argument (str); }; - write data; + write data; }%% @@ -147,7 +148,7 @@ release_string (const version::release_t r) { bool -version::operator > (const version &rhs) const { +version::operator> (const version &rhs) const { unsigned int count = min (m_values.size (), rhs.m_values.size ()); for (unsigned int i = 0; i < count; ++i) diff --git a/version.hpp b/version.hpp index d9dad060..e253d8be 100644 --- a/version.hpp +++ b/version.hpp @@ -17,11 +17,11 @@ * Copyright 2010 Danny Robson */ -#ifndef __VERSION_HPP -#define __VERSION_HPP +#ifndef __UTIL_VERSION_HPP +#define __UTIL_VERSION_HPP +#include #include -#include #include @@ -54,22 +54,20 @@ namespace util { NUM_OFFSETS }; - std::vector m_values; - release_t m_release; + std::array m_values; + size_t m_size; + release_t m_release; void parse (const std::string&); void parse (const char*); public: + unsigned int major (void) const { return m_values[OFFSET_MAJOR]; } + unsigned int minor (void) const { return m_values[OFFSET_MINOR]; } + unsigned int point (void) const { return m_values[OFFSET_POINT]; } + unsigned int build (void) const { return m_values[OFFSET_BUILD]; } - unsigned int major (void) const - { return m_values[OFFSET_MAJOR]; } - unsigned int minor (void) const - { return m_values[OFFSET_MINOR]; } - unsigned int point (void) const - { return m_values[OFFSET_POINT]; } - unsigned int build (void) const - { return m_values[OFFSET_BUILD]; } + size_t size (void) const { return m_size; } bool operator < (const version& rhs) const; bool operator > (const version& rhs) const;