char *
Method_to_s(Method *self) {
static char buf[1024];
sprintf(buf, "__send__(%s, %s, %s)", self->name, self->receiver, self->args);
return strdup(buf);
}
Refactorings
No refactoring yet !
Ants
September 18, 2009, September 18, 2009 02:21, permalink
Least in expensive in terms of CPU, memory, or readability?
Tj Holowaychuk
September 18, 2009, September 18, 2009 20:14, permalink
well a bit of both. just wondering if this is way off. it is just to compile one language to another so it does not need to be really fast
bob
September 19, 2009, September 19, 2009 07:14, permalink
if you are using the GNU C library:
char *Method_to_s(Method *self) {
char *result;
if (asprintf(&result, "__send__(%s, %s, %s)", self->name, self->receiver, self->args))
return NULL; // error
return result;
}
Tj Holowaychuk
September 19, 2009, September 19, 2009 16:56, permalink
does that not produce an error due to returning a local pointer?
Tj Holowaychuk
September 19, 2009, September 19, 2009 16:57, permalink
nvm! just read the description for it
What is the least inexpensive way to have the functionality of below? i am not sure what the best conventions are. global static buffer? malloc'd buffer? locally scoped static buffer like below?