ReactOS 0.4.15-dev-7906-g1b85a5f
index.c File Reference
#include "intsym.h"
#include "index.h"
#include "debug.h"
Include dependency graph for index.c:

Go to the source code of this file.

Functions

static off_t fi_next (struct frame_index *fi)
 
static void fi_shrink (struct frame_index *fi)
 
void fi_init (struct frame_index *fi)
 
void fi_exit (struct frame_index *fi)
 
int fi_resize (struct frame_index *fi, size_t newsize)
 
void fi_add (struct frame_index *fi, off_t pos)
 
int fi_set (struct frame_index *fi, off_t *offsets, off_t step, size_t fill)
 
void fi_reset (struct frame_index *fi)
 

Function Documentation

◆ fi_add()

void fi_add ( struct frame_index fi,
off_t  pos 
)

Definition at line 81 of file index.c.

82{
83 debug3("wanting to add to fill %lu, step %lu, size %lu", (unsigned long)fi->fill, (unsigned long)fi->step, (unsigned long)fi->size);
84 if(fi->fill == fi->size)
85 { /* Index is full, we need to shrink... or grow. */
86 /* Store the current frame number to check later if we still want it. */
87 off_t framenum = fi->fill*fi->step;
88 /* If we want not / cannot grow, we shrink. */
89 if( !(fi->grow_size && fi_resize(fi, fi->size+fi->grow_size)==0) )
90 fi_shrink(fi);
91
92 /* Now check if we still want to add this frame (could be that not, because of changed step). */
93 if(fi->next != framenum) return;
94 }
95 /* When we are here, we want that frame. */
96 if(fi->fill < fi->size) /* safeguard for size=1, or just generally */
97 {
98 debug1("adding to index at %p", (void*)(fi->data+fi->fill));
99 fi->data[fi->fill] = pos;
100 ++fi->fill;
101 fi->next = fi_next(fi);
102 debug3("added pos %li to index with fill %lu and step %lu", (long) pos, (unsigned long)fi->fill, (unsigned long)fi->step);
103 }
104}
__kernel_off_t off_t
Definition: linux.h:201
#define fi_resize
Definition: intsym.h:219
#define debug1(s, a)
Definition: debug.h:61
#define debug3(s, a, b, c)
Definition: debug.h:63
static off_t fi_next(struct frame_index *fi)
Definition: index.c:15
static void fi_shrink(struct frame_index *fi)
Definition: index.c:22
off_t next
Definition: index.h:30
size_t grow_size
Definition: index.h:33
size_t fill
Definition: index.h:32
off_t step
Definition: index.h:29
off_t * data
Definition: index.h:28
size_t size
Definition: index.h:31

◆ fi_exit()

void fi_exit ( struct frame_index fi)

Definition at line 49 of file index.c.

50{
51 debug2("fi_exit: %p and %lu", (void*)fi->data, (unsigned long)fi->size);
52 if(fi->size && fi->data != NULL) free(fi->data);
53
54 fi_init(fi); /* Be prepared for further fun, still. */
55}
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define fi_init
Definition: intsym.h:217
#define debug2(s, a, b)
Definition: debug.h:62

◆ fi_init()

void fi_init ( struct frame_index fi)

Definition at line 39 of file index.c.

40{
41 fi->data = NULL;
42 fi->step = 1;
43 fi->fill = 0;
44 fi->size = 0;
45 fi->grow_size = 0;
46 fi->next = fi_next(fi);
47}

◆ fi_next()

static off_t fi_next ( struct frame_index fi)
static

Definition at line 15 of file index.c.

16{
17 return (off_t)fi->fill*fi->step;
18}

Referenced by fi_add(), fi_init(), fi_reset(), fi_resize(), fi_set(), and fi_shrink().

◆ fi_reset()

void fi_reset ( struct frame_index fi)

Definition at line 126 of file index.c.

127{
128 debug1("reset with size %"SIZE_P, (size_p)fi->size);
129 fi->fill = 0;
130 fi->step = 1;
131 fi->next = fi_next(fi);
132}
#define SIZE_P
Definition: compat.h:139
unsigned long size_p
Definition: compat.h:140

◆ fi_resize()

int fi_resize ( struct frame_index fi,
size_t  newsize 
)

Definition at line 57 of file index.c.

58{
59 off_t *newdata = NULL;
60 if(newsize == fi->size) return 0;
61
62 if(newsize > 0 && newsize < fi->size)
63 { /* When we reduce buffer size a bit, shrink stuff. */
64 while(fi->fill > newsize){ fi_shrink(fi); }
65 }
66
67 newdata = safe_realloc(fi->data, newsize*sizeof(off_t));
68 if(newsize == 0 || newdata != NULL)
69 {
70 fi->data = newdata;
71 fi->size = newsize;
72 if(fi->fill > fi->size) fi->fill = fi->size;
73
74 fi->next = fi_next(fi);
75 debug2("new index of size %lu at %p", (unsigned long)fi->size, (void*)fi->data);
76 return 0;
77 } else
78 return -1;
79}
GLsizeiptr size
Definition: glext.h:5919
#define safe_realloc
Definition: intsym.h:10

◆ fi_set()

int fi_set ( struct frame_index fi,
off_t offsets,
off_t  step,
size_t  fill 
)

Definition at line 106 of file index.c.

107{
108 if(fi_resize(fi, fill) == -1) return -1;
109 fi->step = step;
110 if(offsets != NULL)
111 {
112 memcpy(fi->data, offsets, fill*sizeof(off_t));
113 fi->fill = fill;
114 }
115 else
116 {
117 /* allocation only, no entries in index yet */
118 fi->fill = 0;
119 }
120 fi->next = fi_next(fi);
121 debug3("set new index of fill %lu, size %lu at %p",
122 (unsigned long)fi->fill, (unsigned long)fi->size, (void*)fi->data);
123 return 0;
124}
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algobase.h:449
static const FxOffsetAndName offsets[]
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ fi_shrink()

static void fi_shrink ( struct frame_index fi)
static

Definition at line 22 of file index.c.

23{
24 if(fi->fill < 2) return; /* Won't shrink below 1. */
25 else
26 { /* Double the step, half the fill. Should work as well for fill%2 = 1 */
27 size_t c;
28 debug2("shrink index with fill %lu and step %lu", (unsigned long)fi->fill, (unsigned long)fi->step);
29 fi->step *= 2;
30 fi->fill /= 2;
31 /* Move the data down. */
32 for(c = 0; c < fi->fill; ++c)
33 fi->data[c] = fi->data[2*c];
34 }
35
36 fi->next = fi_next(fi);
37}
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80

Referenced by fi_add(), and fi_resize().