This patch is a minor performance tweak.
The existing code often uses buffer_add() to append a single character
to a growing buffer. In these cases the new version uses the
OSRF_BUFFER_ADD_CHAR macro instead.
At one time, buffer_add_char() added a single character by creating
a one-character string and passing it to buffer_add(). It was more
efficient to call buffer_add() directly, even for a single character.
The current implementation of buffer_add_char() does not rely on
buffer_add(), nor does the corresponding macro OSRF_BUFFER_ADD_CHAR.
They are faster than buffer_add() because they don't have to call any
functions such as strlen() or strcpy() for a one-character string.
Scott McKellar
http://home.swbell.net/mck9/ct/
Developer's Certificate of Origin 1.1 By making a contribution to
this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license indicated
in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source license
and I have the right under that license to submit that work with
modifications, whether created in whole or in part by me, under the
same open source license (unless I am permitted to submit under a
different license), as indicated in the file; or
(c) The contribution was provided directly to me by some other person
who certified (a), (b) or (c) and I have not modified it; and
(d) In the case of each of (a), (b), or (c), I understand and agree
that this project and the contribution are public and that a record
of the contribution (including all personal information I submit
with it, including my sign-off) is maintained indefinitely and may
be redistributed consistent with this project or the open source
license indicated in the file.
*** ./trunk/Open-ILS/src/c-apps/oils_cstore.c 2008-12-13 18:46:33.000000000 -0600
--- ./trunk-mod/Open-ILS/src/c-apps/oils_cstore.c 2008-12-13 19:11:49.000000000 -0600
***************
*** 800,806 ****
growing_buffer* val_buf = buffer_init(128);
buffer_fadd(table_buf,"INSERT INTO %s", osrfHashGet(meta, "tablename"));
! buffer_add(col_buf,"(");
buffer_add(val_buf,"VALUES (");
--- 800,806 ----
growing_buffer* val_buf = buffer_init(128);
buffer_fadd(table_buf,"INSERT INTO %s", osrfHashGet(meta, "tablename"));
! OSRF_BUFFER_ADD_CHAR(col_buf,'(');
buffer_add(val_buf,"VALUES (");
***************
*** 841,848 ****
if (first) {
first = 0;
} else {
! buffer_add(col_buf, ",");
! buffer_add(val_buf, ",");
}
buffer_add(col_buf, field_name);
--- 841,848 ----
if (first) {
first = 0;
} else {
! OSRF_BUFFER_ADD_CHAR(col_buf, ',');
! OSRF_BUFFER_ADD_CHAR(val_buf, ',');
}
buffer_add(col_buf, field_name);
***************
*** 887,894 ****
}
! buffer_add(col_buf,")");
! buffer_add(val_buf,")");
char* table_str = buffer_release(table_buf);
char* col_str = buffer_release(col_buf);
--- 887,894 ----
}
! OSRF_BUFFER_ADD_CHAR(col_buf,')');
! OSRF_BUFFER_ADD_CHAR(val_buf,')');
char* table_str = buffer_release(table_buf);
char* col_str = buffer_release(col_buf);
***************
*** 1098,1107 ****
}
}
! buffer_add(
! sql_buf,
! ")"
! );
return buffer_release(sql_buf);
}
--- 1098,1104 ----
}
}
! OSRF_BUFFER_ADD_CHAR( sql_buf, ')' );
return buffer_release(sql_buf);
}
***************
*** 1900,1906 ****
if (first) {
first = 0;
} else {
! buffer_add(select_buf, ",");
}
if (locale) {
--- 1897,1903 ----
if (first) {
first = 0;
} else {
! OSRF_BUFFER_ADD_CHAR(select_buf, ',');
}
if (locale) {
***************
*** 1933,1939 ****
if (first) {
first = 0;
} else {
! buffer_add(select_buf, ",");
}
if ((tmp_const = jsonObjectGetKeyConst( selfield, "alias" ))) {
--- 1930,1936 ----
if (first) {
first = 0;
} else {
! OSRF_BUFFER_ADD_CHAR(select_buf, ',');
}
if ((tmp_const = jsonObjectGetKeyConst( selfield, "alias" ))) {
***************
*** 1976,1982 ****
if (gfirst) {
gfirst = 0;
} else {
! buffer_add(group_buf, ",");
}
buffer_fadd(group_buf, " %d", sel_pos);
--- 1973,1979 ----
if (gfirst) {
gfirst = 0;
} else {
! OSRF_BUFFER_ADD_CHAR(group_buf, ',');
}
buffer_fadd(group_buf, " %d", sel_pos);
***************
*** 1985,1991 ****
if (gfirst) {
gfirst = 0;
} else {
! buffer_add(group_buf, ",");
}
__column = searchFieldTransform(cname, field, selfield);
--- 1982,1988 ----
if (gfirst) {
gfirst = 0;
} else {
! OSRF_BUFFER_ADD_CHAR(group_buf, ',');
}
__column = searchFieldTransform(cname, field, selfield);
***************
*** 2008,2014 ****
if (is_agg) jsonObjectFree(is_agg);
} else {
! buffer_add(select_buf, "*");
}
--- 2005,2011 ----
if (is_agg) jsonObjectFree(is_agg);
} else {
! OSRF_BUFFER_ADD_CHAR(select_buf, '*');
}
***************
*** 2255,2261 ****
free(string);
}
! if (!(flags & SUBSELECT)) buffer_add(sql_buf, ";");
free(core_class);
if (defaultselhash) jsonObjectFree(defaultselhash);
--- 2252,2258 ----
free(string);
}
! if (!(flags & SUBSELECT)) OSRF_BUFFER_ADD_CHAR(sql_buf, ';');
free(core_class);
if (defaultselhash) jsonObjectFree(defaultselhash);
***************
*** 2335,2341 ****
if (first) {
first = 0;
} else {
! buffer_add(select_buf, ",");
}
if (locale) {
--- 2332,2338 ----
if (first) {
first = 0;
} else {
! OSRF_BUFFER_ADD_CHAR(select_buf, ',');
}
if (locale) {
***************
*** 2523,2529 ****
if (defaultselhash) jsonObjectFree(defaultselhash);
! buffer_add(sql_buf, ";");
return buffer_release(sql_buf);
}
--- 2520,2526 ----
if (defaultselhash) jsonObjectFree(defaultselhash);
! OSRF_BUFFER_ADD_CHAR(sql_buf, ';');
return buffer_release(sql_buf);
}
***************
*** 3021,3033 ****
if (!field_object || field_object->type == JSON_NULL) {
if ( !(!( strcmp( osrfHashGet(meta, "classname"), "au" ) ) && !( strcmp( field_name, "passwd" ) )) ) { // arg at the special case!
if (first) first = 0;
! else buffer_add(sql, ",");
buffer_fadd( sql, " %s = NULL", field_name );
}
} else if ( !strcmp(osrfHashGet(field, "primitive"), "number") ) {
if (first) first = 0;
! else buffer_add(sql, ",");
if ( !strncmp(osrfHashGet(field, "datatype"), "INT", (size_t)3) ) {
buffer_fadd( sql, " %s = %ld", field_name, atol(value) );
--- 3018,3030 ----
if (!field_object || field_object->type == JSON_NULL) {
if ( !(!( strcmp( osrfHashGet(meta, "classname"), "au" ) ) && !( strcmp( field_name, "passwd" ) )) ) { // arg at the special case!
if (first) first = 0;
! else OSRF_BUFFER_ADD_CHAR(sql, ',');
buffer_fadd( sql, " %s = NULL", field_name );
}
} else if ( !strcmp(osrfHashGet(field, "primitive"), "number") ) {
if (first) first = 0;
! else OSRF_BUFFER_ADD_CHAR(sql, ',');
if ( !strncmp(osrfHashGet(field, "datatype"), "INT", (size_t)3) ) {
buffer_fadd( sql, " %s = %ld", field_name, atol(value) );
***************
*** 3040,3046 ****
} else {
if ( dbi_conn_quote_string(dbhandle, &value) ) {
if (first) first = 0;
! else buffer_add(sql, ",");
buffer_fadd( sql, " %s = %s", field_name, value );
} else {
--- 3037,3043 ----
} else {
if ( dbi_conn_quote_string(dbhandle, &value) ) {
if (first) first = 0;
! else OSRF_BUFFER_ADD_CHAR(sql, ',');
buffer_fadd( sql, " %s = %s", field_name, value );
} else {