Skip to content

Commit 9d871c2

Browse files
committed
Rewrite table_is_system for clarity, extensibility
Previous version was a hot mess: casting strings to strings, using a sentinel value to mark the end of an array, using a while loop where a for loop was appropriate, nesting all function logic in one branch of an if statement. Why even. This version is much cleaner, and it begins with a std::vector, which means we can (in commits to follow) add elements to it based on command-line options.
1 parent 4c44738 commit 9d871c2

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

storage/innobase/dict/mem.cc

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,35 +147,27 @@ void dict_mem_table_free(dict_table_t *table) /*!< in: table */
147147
}
148148

149149
/** System databases */
150-
static std::string innobase_system_databases[] = {
151-
"mysql/", "information_schema/", "performance_schema/", ""};
150+
static std::vector<std::string> innobase_system_databases({
151+
"mysql/", "information_schema/", "performance_schema/"
152+
});
152153

153154
/** Determines if a table is a system table
154155
@param[in] name table_name
155156
@return true if table is system table */
156-
static bool dict_mem_table_is_system(const std::string name) {
157+
static bool dict_mem_table_is_system(const std::string &name) {
157158
/* Table has the following format: database/table and some system table are
158159
of the form SYS_* */
159-
if (name.find('/') != std::string::npos) {
160-
size_t table_len = name.length();
161-
162-
std::string system_db = std::string(innobase_system_databases[0]);
163-
int i = 0;
164-
165-
while (system_db.compare("") != 0) {
166-
size_t len = system_db.length();
167-
168-
if (table_len > len && name.compare(0, len, system_db) == 0) {
169-
return true;
170-
}
160+
if (name.find('/') == std::string::npos) {
161+
return true;
162+
}
171163

172-
system_db = std::string(innobase_system_databases[++i]);
164+
for (auto p : innobase_system_databases) {
165+
if (name.length() > p.length() && name.compare(0, p.length(), p) == 0) {
166+
return true;
173167
}
174-
175-
return false;
176-
} else {
177-
return true;
178168
}
169+
170+
return false;
179171
}
180172

181173
/** Creates a table memory object.

0 commit comments

Comments
 (0)