Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If statement optimization #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions lib/xlsxio_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,17 +764,15 @@ void main_sheet_list_expat_callback_element_start (void* callbackdata, const XML
const XML_Char* sheetname;
//const XML_Char* relid = get_expat_attr_by_name(atts, X("r:id"));
if ((sheetname = get_expat_attr_by_name(atts, X("name"))) != NULL) {
if (data->callback) {
if ((*data->callback)(sheetname, data->callbackdata) != 0) {
XML_StopParser(data->xmlparser, XML_FALSE);
return;
}
if ((*data->callback)(sheetname, data->callbackdata) != 0) {
XML_StopParser(data->xmlparser, XML_FALSE);
return;
}
/*
} else {
//for non-calback method suspend here
XML_StopParser(data->xmlparser, XML_TRUE);
} else {
//for non-calback method suspend here
XML_StopParser(data->xmlparser, XML_TRUE);
*/
}
}
}
}
Expand Down Expand Up @@ -1142,7 +1140,7 @@ void data_sheet_expat_callback_find_cell_start (void* callbackdata, const XML_Ch
if ((data->flags & XLSXIOREAD_SKIP_EXTRA_CELLS) && data->cols > 0 && cellmax > data->cols)
cellmax = data->cols;
while (data->colnr < cellmax) {
if (data->colnr > 0 && data->sheet_cell_callback) {
if (data->sheet_cell_callback) {
if ((*data->sheet_cell_callback)(data->rownr, data->colnr + 1, NULL, data->callbackdata)) {
XML_StopParser(data->xmlparser, XML_FALSE);
return;
Expand Down
42 changes: 20 additions & 22 deletions lib/xlsxio_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,30 +915,28 @@ void write_cell_data (xlsxiowriter handle, const char* rowattr, const char* pref
if (suffix)
append_data(&handle->buf, &handle->buflen, suffix);
//collect cell information
if (!handle->sheetopen) {
if (!*handle->pcurrentcolumn) {
//create new column information structure
struct column_info_struct* colinfo;
if ((colinfo = (struct column_info_struct*)malloc(sizeof(struct column_info_struct))) != NULL) {
colinfo->width = 0;
colinfo->maxwidth = 0;
colinfo->next = NULL;
*handle->pcurrentcolumn = colinfo;
}
}
//keep track of biggest column width
if (data) {
//only count first line in multiline data
char* p = strchr(data, '\n');
if (p)
datalen = p - data;
//remember this length if it is the longest one so far
if (datalen > 0 && datalen > (*handle->pcurrentcolumn)->maxwidth)
(*handle->pcurrentcolumn)->maxwidth = datalen;
if (!*handle->pcurrentcolumn) {
//create new column information structure
struct column_info_struct* colinfo;
if ((colinfo = (struct column_info_struct*)malloc(sizeof(struct column_info_struct))) != NULL) {
colinfo->width = 0;
colinfo->maxwidth = 0;
colinfo->next = NULL;
*handle->pcurrentcolumn = colinfo;
}
//prepare for the next column
handle->pcurrentcolumn = &(*handle->pcurrentcolumn)->next;
}
//keep track of biggest column width
if (data) {
//only count first line in multiline data
char* p = strchr(data, '\n');
if (p)
datalen = p - data;
//remember this length if it is the longest one so far
if (datalen > 0 && datalen > (*handle->pcurrentcolumn)->maxwidth)
(*handle->pcurrentcolumn)->maxwidth = datalen;
}
//prepare for the next column
handle->pcurrentcolumn = &(*handle->pcurrentcolumn)->next;
}
#if !defined(NO_ROW_NUMBERS) && !defined(NO_COLUMN_NUMBERS)
free(cellcoord);
Expand Down
Loading