Commit 15424478 authored by topjohnwu's avatar topjohnwu

Reuse buffer

parent a6f0aff6
...@@ -49,8 +49,7 @@ class Extra { ...@@ -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: ...@@ -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: ...@@ -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);
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment