[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] Request for review
From: |
Greg Chicares |
Subject: |
[lmi] Request for review |
Date: |
Mon, 16 Jan 2017 01:28:36 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 |
Does this patch (on top of your github pull/52) seem correct?
First of all, static_get_db_names()'s implementation really is all
static, so after it has been called once, calling it again just
returns a const reference to a static object. It seems wasteful
and, more important, needlessly verbose to store static copies of
it in two other functions.
And static_get_short_names() sounds like static_get_db_names(), but
its implementation is not all static--it does work every time it's
called, and there's no appealing way to avoid that--so it should be
renamed to prevent confusion, and it really does make sense to store
a static copy of it in the one function that calls it.
---------8<--------8<--------8<--------8<--------8<--------8<--------8<-------
--- a00/52b/dbnames.cpp 2017-01-13 15:32:07.000000000 +0000
+++ a00/dbnames.cpp 2017-01-16 01:09:23.756255084 +0000
@@ -85,11 +85,10 @@
return v;
}
-std::map<std::string,int> static_get_short_names()
+std::map<std::string,int> short_name_to_key_map()
{
std::map<std::string,int> m;
- static std::vector<db_names> const names = static_get_db_names();
- for(auto const& name: names)
+ for(auto const& name : static_get_db_names())
{
m[name.ShortName] = name.Idx;
}
@@ -105,14 +104,13 @@
int db_key_from_name(std::string const& name)
{
- static std::map<std::string,int> const m = static_get_short_names();
+ static std::map<std::string,int> const m = short_name_to_key_map();
return map_lookup(m, name);
}
std::string db_name_from_key(int key)
{
- static std::vector<db_names> const names = static_get_db_names();
LMI_ASSERT(0 <= key && key < DB_LAST);
- return names[key].ShortName;
+ return static_get_db_names()[key].ShortName;
}
--------->8-------->8-------->8-------->8-------->8-------->8-------->8-------
- Re: [lmi] Request for review, (continued)
- Re: [lmi] Request for review, Greg Chicares, 2017/01/11
- Re: [lmi] Request for review, Vadim Zeitlin, 2017/01/11
- Re: [lmi] Request for review, Greg Chicares, 2017/01/12
- Re: [lmi] Request for review, Greg Chicares, 2017/01/12
- Re: [lmi] Request for review, Greg Chicares, 2017/01/12
- Re: [lmi] Request for review, Vadim Zeitlin, 2017/01/12
- Re: [lmi] Request for review, Greg Chicares, 2017/01/12
- Re: [lmi] Request for review, Vadim Zeitlin, 2017/01/12
- Re: [lmi] Request for review, Greg Chicares, 2017/01/12
- Re: [lmi] Request for review, Vadim Zeitlin, 2017/01/13
[lmi] Request for review,
Greg Chicares <=