Reuse buffer

This commit is contained in:
topjohnwu 2019-11-13 02:36:45 -05:00
parent a6f0aff659
commit 1542447822

View File

@ -49,8 +49,7 @@ class Extra {
bool bool_val; bool bool_val;
const char * str_val; const char * str_val;
}; };
char i_buf[16]; char buf[32];
char b_buf[32];
public: public:
Extra(const char *k, int v): key(k), type(INT), int_val(v) {} Extra(const char *k, int v): key(k), type(INT), int_val(v) {}
Extra(const char *k, bool v): key(k), type(BOOL), bool_val(v) {} Extra(const char *k, bool v): key(k), type(BOOL), bool_val(v) {}
@ -61,8 +60,8 @@ public:
switch (type) { switch (type) {
case INT: case INT:
vec.push_back("--ei"); vec.push_back("--ei");
sprintf(i_buf, "%d", int_val); sprintf(buf, "%d", int_val);
val = i_buf; val = buf;
break; break;
case BOOL: case BOOL:
vec.push_back("--ez"); vec.push_back("--ez");
@ -80,17 +79,17 @@ public:
void add_bind(vector<const char *> &vec) { void add_bind(vector<const char *> &vec) {
switch (type) { switch (type) {
case INT: case INT:
sprintf(b_buf, "%s:i:%d", key, int_val); sprintf(buf, "%s:i:%d", key, int_val);
break; break;
case BOOL: case BOOL:
sprintf(b_buf, "%s:b:%s", key, bool_val ? "true" : "false"); sprintf(buf, "%s:b:%s", key, bool_val ? "true" : "false");
break; break;
case STRING: case STRING:
sprintf(b_buf, "%s:s:%s", key, str_val); sprintf(buf, "%s:s:%s", key, str_val);
break; break;
} }
vec.push_back("--extra"); vec.push_back("--extra");
vec.push_back(b_buf); vec.push_back(buf);
} }
}; };