Changeset e5d4294 in mainline for uspace/app/edit/sheet.c
- Timestamp:
- 2009-09-16T21:31:46Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 57688fe2
- Parents:
- 8c73012 (diff), 743e17b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/sheet.c
r8c73012 re5d4294 54 54 #include <adt/list.h> 55 55 #include <align.h> 56 #include <macros.h> 56 57 57 58 #include "sheet.h" 58 59 59 60 enum { 60 TAB_WIDTH = 8 61 TAB_WIDTH = 8, 62 63 /** Initial of dat buffer in bytes */ 64 INITIAL_SIZE = 32 61 65 }; 62 66 … … 64 68 int sheet_init(sheet_t *sh) 65 69 { 66 sh->dbuf_size = 65536;70 sh->dbuf_size = INITIAL_SIZE; 67 71 sh->text_size = 0; 68 72 … … 95 99 link_t *link; 96 100 tag_t *tag; 101 char *newp; 97 102 98 103 sz = str_size(str); 99 if (sh->text_size + sz > sh->dbuf_size) 100 return ELIMIT; 104 if (sh->text_size + sz > sh->dbuf_size) { 105 /* Enlarge data buffer. */ 106 newp = realloc(sh->data, sh->dbuf_size * 2); 107 if (newp == NULL) 108 return ELIMIT; 109 110 sh->data = newp; 111 sh->dbuf_size = sh->dbuf_size * 2; 112 } 101 113 102 114 ipp = sh->data + pos->b_off; 103 115 116 /* Copy data. */ 104 117 memmove(ipp + sz, ipp, sh->text_size - pos->b_off); 105 118 memcpy(ipp, str, sz); 106 119 sh->text_size += sz; 107 120 108 /* Adjust tags */121 /* Adjust tags. */ 109 122 110 123 link = sh->tags_head.next; … … 139 152 link_t *link; 140 153 tag_t *tag; 154 char *newp; 155 size_t shrink_size; 141 156 142 157 spp = sh->data + spos->b_off; … … 146 161 sh->text_size -= sz; 147 162 148 /* Adjust tags */163 /* Adjust tags. */ 149 164 link = sh->tags_head.next; 150 165 while (link != &sh->tags_head) { … … 158 173 link = link->next; 159 174 } 160 175 176 /* See if we should free up some memory. */ 177 shrink_size = max(sh->dbuf_size / 4, INITIAL_SIZE); 178 if (sh->text_size <= shrink_size && sh->dbuf_size > INITIAL_SIZE) { 179 /* Shrink data buffer. */ 180 newp = realloc(sh->data, shrink_size); 181 if (newp == NULL) { 182 /* Failed to shrink buffer... no matter. */ 183 return EOK; 184 } 185 186 sh->data = newp; 187 sh->dbuf_size = shrink_size; 188 } 189 161 190 return EOK; 162 191 }
Note:
See TracChangeset
for help on using the changeset viewer.