A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Reorganize mallocator.c, and add the possibility to disable mallocators.
[simgrid.git]
/
src
/
xbt
/
xbt_strbuff.c
diff --git
a/src/xbt/xbt_strbuff.c
b/src/xbt/xbt_strbuff.c
index
abf0a0d
..
16835fd
100644
(file)
--- a/
src/xbt/xbt_strbuff.c
+++ b/
src/xbt/xbt_strbuff.c
@@
-23,11
+23,10
@@
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(strbuff, xbt, "String buffers");
** Buffer code
**/
** Buffer code
**/
-void xbt_strbuff_empty(xbt_strbuff_t b)
+
XBT_INLINE
void xbt_strbuff_empty(xbt_strbuff_t b)
{
b->used = 0;
{
b->used = 0;
- b->data[0] = '\n';
- b->data[1] = '\0';
+ b->data[0] = '\0';
}
xbt_strbuff_t xbt_strbuff_new(void)
}
xbt_strbuff_t xbt_strbuff_new(void)
@@
-43,7
+42,7
@@
xbt_strbuff_t xbt_strbuff_new(void)
*
* Beware, we store the ctn directly, not a copy of it
*/
*
* Beware, we store the ctn directly, not a copy of it
*/
-xbt_strbuff_t xbt_strbuff_new_from(char *ctn)
+
XBT_INLINE
xbt_strbuff_t xbt_strbuff_new_from(char *ctn)
{
xbt_strbuff_t res = malloc(sizeof(s_xbt_strbuff_t));
res->data = ctn;
{
xbt_strbuff_t res = malloc(sizeof(s_xbt_strbuff_t));
res->data = ctn;
@@
-52,17
+51,16
@@
xbt_strbuff_t xbt_strbuff_new_from(char *ctn)
}
/** @brief frees only the container without touching to the contained string */
}
/** @brief frees only the container without touching to the contained string */
-void xbt_strbuff_free_container(xbt_strbuff_t b)
+
XBT_INLINE
void xbt_strbuff_free_container(xbt_strbuff_t b)
{
free(b);
}
/** @brief frees the buffer and its content */
{
free(b);
}
/** @brief frees the buffer and its content */
-void xbt_strbuff_free(xbt_strbuff_t b)
+
XBT_INLINE
void xbt_strbuff_free(xbt_strbuff_t b)
{
if (b) {
{
if (b) {
- if (b->data)
- free(b->data);
+ free(b->data);
free(b);
}
}
free(b);
}
}
@@
-79,24
+77,22
@@
void xbt_strbuff_append(xbt_strbuff_t b, const char *toadd)
needed_space = b->used + addlen + 1;
if (needed_space > b->size) {
needed_space = b->used + addlen + 1;
if (needed_space > b->size) {
- b->data =
- realloc(b->data, MAX(minimal_increment + b->used, needed_space));
b->size = MAX(minimal_increment + b->used, needed_space);
b->size = MAX(minimal_increment + b->used, needed_space);
+ b->data = realloc(b->data, b->size);
}
strcpy(b->data + b->used, toadd);
b->used += addlen;
}
}
strcpy(b->data + b->used, toadd);
b->used += addlen;
}
-void xbt_strbuff_chomp(xbt_strbuff_t b)
+
XBT_INLINE
void xbt_strbuff_chomp(xbt_strbuff_t b)
{
{
- while (b->data[b->used] == '\n') {
+ while (b->used && b->data[b->used - 1] == '\n') {
+ b->used--;
b->data[b->used] = '\0';
b->data[b->used] = '\0';
- if (b->used)
- b->used--;
}
}
}
}
-void xbt_strbuff_trim(xbt_strbuff_t b)
+
XBT_INLINE
void xbt_strbuff_trim(xbt_strbuff_t b)
{
xbt_str_trim(b->data, " ");
b->used = strlen(b->data);
{
xbt_str_trim(b->data, " ");
b->used = strlen(b->data);
@@
-275,8
+271,7
@@
void xbt_strbuff_varsubst(xbt_strbuff_t b, xbt_dict_t patterns)
}
free(value);
}
free(value);
- if (default_value)
- free(default_value);
+ free(default_value);
end--; /* compensate the next end++ */
}
end--; /* compensate the next end++ */
}