ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/dynbuf.h
(Generate patch)

Comparing deliantra/server/include/dynbuf.h (file contents):
Revision 1.6 by root, Mon Apr 30 17:39:58 2007 UTC vs.
Revision 1.9 by root, Sun May 27 23:22:29 2007 UTC

2#define DYNBUF_H__ 2#define DYNBUF_H__
3 3
4#include <cstring> 4#include <cstring>
5#include <cassert> 5#include <cassert>
6 6
7#include "util.h"
7#include "shstr.h" 8#include "shstr.h"
8 9
9// this is a "buffer" that can grow fast 10// this is a "buffer" that can grow fast
10// and is still somewhat space-efficient. 11// and is still somewhat space-efficient.
11// unlike obstacks or other data structures, 12// unlike obstacks or other data structures,
28 int _size; 29 int _size;
29 30
30 chunk *first, *last; 31 chunk *first, *last;
31 32
32 void _reserve (int size); 33 void _reserve (int size);
34 void _clear ();
33 void clear (); 35 void clear ();
34 void finish (); 36 void finish ();
35 37
36public: 38public:
37 39
46 48
47 int room () const { return end - ptr; } 49 int room () const { return end - ptr; }
48 50
49 char *force (int size) 51 char *force (int size)
50 { 52 {
51 if (ptr + size >= end) 53 if (expect_false (ptr + size >= end))
52 _reserve (size); 54 _reserve (size);
53 55
54 return ptr; 56 return ptr;
55 } 57 }
56 58
57 char *alloc (int size) 59 char *alloc (int size)
58 { 60 {
59 char *res = force (size); 61 char *res = force (size);
60 ptr += size; 62 ptr += size;
61 return res; 63 return res;
62 } 64 }
63 65
64 void fadd (char c) { *ptr++ = c; } 66 void fadd (char c) { *ptr++ = c; }
65 void fadd (unsigned char c) { fadd (char (c)); } 67 void fadd (unsigned char c) { fadd (char (c)); }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines