Changes in uspace/app/edit/sheet.c [c29f20b:3052ff4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/sheet.c
rc29f20b r3052ff4 54 54 #include <adt/list.h> 55 55 #include <align.h> 56 #include <macros.h>57 56 58 57 #include "sheet.h" 59 58 60 59 enum { 61 TAB_WIDTH = 8, 62 63 /** Initial of dat buffer in bytes */ 64 INITIAL_SIZE = 32 60 TAB_WIDTH = 8 65 61 }; 66 62 … … 68 64 int sheet_init(sheet_t *sh) 69 65 { 70 sh->dbuf_size = INITIAL_SIZE;66 sh->dbuf_size = 65536; 71 67 sh->text_size = 0; 72 68 … … 99 95 link_t *link; 100 96 tag_t *tag; 101 char *newp;102 97 103 98 sz = str_size(str); 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 } 99 if (sh->text_size + sz > sh->dbuf_size) 100 return ELIMIT; 113 101 114 102 ipp = sh->data + pos->b_off; 115 103 116 /* Copy data. */117 104 memmove(ipp + sz, ipp, sh->text_size - pos->b_off); 118 105 memcpy(ipp, str, sz); 119 106 sh->text_size += sz; 120 107 121 /* Adjust tags .*/108 /* Adjust tags */ 122 109 123 110 link = sh->tags_head.next; … … 152 139 link_t *link; 153 140 tag_t *tag; 154 char *newp;155 size_t shrink_size;156 141 157 142 spp = sh->data + spos->b_off; … … 161 146 sh->text_size -= sz; 162 147 163 /* Adjust tags .*/148 /* Adjust tags */ 164 149 link = sh->tags_head.next; 165 150 while (link != &sh->tags_head) { … … 173 158 link = link->next; 174 159 } 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 160 190 161 return EOK; 191 162 }
Note:
See TracChangeset
for help on using the changeset viewer.