Skip to content

Commit a74f282

Browse files
committed
On the better-pristines branch: Make a minor improvement to the internal
spillbuf API and its documentation. No funcitonal change. * subversion/include/private/svn_subr_private.h (SVN_SPILLBUF__DELETE_ON_CLOSE, SVN_SPILLBUF__SPILL_ALL_CONTENTS): New flag constants. (svn_spillbuf__create_extended): Use a parameter with bitwise flags instead of a series of boolean arguments. This makes calls of this function self-documenting. (svn_spillbuf__create): Improve the documentation. * subversion/libsvn_subr/spillbuf.c (struct svn_spillbuf_t): Move the byte-sized boolean flags to the end of the struct, possibly reducing space used by alignment padding. (init_spillbuf, init_spillbuf_extended): Remove single-use private functions. (svn_spillbuf__create_extended): Update the parameters and inline the code that was previously in init_spillbuf_extended(). (svn_spillbuf__create): Call svn_spillbuf__create_extended(). * subversion/tests/libsvn_subr/spillbuf-test.c: Update all calls to svn_spillbuf__create_extended() to reflect its changed parameters. git-svn-id: https://svn.apache.org/repos/asf/subversion/branches/better-pristines@1931378 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5e0a53f commit a74f282

File tree

3 files changed

+60
-72
lines changed

3 files changed

+60
-72
lines changed

subversion/include/private/svn_subr_private.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,35 @@ extern "C" {
8989
typedef struct svn_spillbuf_t svn_spillbuf_t;
9090

9191

92-
/* Create a spill buffer. */
93-
svn_spillbuf_t *
94-
svn_spillbuf__create(apr_size_t blocksize,
95-
apr_size_t maxsize,
96-
apr_pool_t *result_pool);
97-
98-
/* Create a spill buffer, with extra parameters. */
92+
/* Delete all files created by spillbuf operations when the spillbuf
93+
is destroyed. This is the behaviour of svn_spilbuff__create(). */
94+
#define SVN_SPILLBUF__DELETE_ON_CLOSE 0x01
95+
96+
/* When maxsize is reached, spill all contents buffered in memory to the
97+
spill file, not just the overflow. This ensures that the spill file,
98+
if one is created, will contain all the data written to the spillbuf. */
99+
#define SVN_SPILLBUF__SPILL_ALL_CONTENTS 0x02
100+
101+
/* Create a spill buffer. FLAGS is a bitwise-or combination of the
102+
constants defined above. See svn_io_open_unique_file3() in svn_io.h
103+
for a description of the semantics of the DIRPATH parameter. */
99104
svn_spillbuf_t *
100105
svn_spillbuf__create_extended(apr_size_t blocksize,
101106
apr_size_t maxsize,
102-
svn_boolean_t delete_on_close,
103-
svn_boolean_t spill_all_contents,
107+
unsigned flags,
104108
const char* dirpath,
105109
apr_pool_t *result_pool);
106110

111+
/* Create a spill buffer with:
112+
FLAGS = SVN_SPILLBUF__DELETE_ON_CLOSE
113+
DIRPATH = NULL
114+
The created spillbuf's behaviour is what we need when it's used as
115+
a temporary buffer for connecting push-like and pull-like streams. */
116+
svn_spillbuf_t *
117+
svn_spillbuf__create(apr_size_t blocksize,
118+
apr_size_t maxsize,
119+
apr_pool_t *result_pool);
120+
107121
/* Determine how much content is stored in the spill buffer. */
108122
svn_filesize_t
109123
svn_spillbuf__get_size(const svn_spillbuf_t *buf);

subversion/libsvn_subr/spillbuf.c

Lines changed: 21 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ struct svn_spillbuf_t {
7474
/* How much content remains in SPILL. */
7575
svn_filesize_t spill_size;
7676

77+
/* The directory in which the spill file is created. */
78+
const char *dirpath;
79+
80+
/* The name of the temporary spill file. */
81+
const char *filename;
82+
7783
/* When false, do not delete the spill file when it is closed. */
7884
svn_boolean_t delete_on_close;
7985

8086
/* When true, and the amount of data written to the spillbuf is
8187
larger than MAXSIZE, all spillbuf contents will be written to the
8288
spill file. */
8389
svn_boolean_t spill_all_contents;
84-
85-
/* The directory in which the spill file is created. */
86-
const char *dirpath;
87-
88-
/* The name of the temporary spill file. */
89-
const char *filename;
9090
};
9191

9292

@@ -112,62 +112,33 @@ struct svn_spillbuf_reader_t {
112112
apr_size_t save_pos;
113113
};
114114

115-
116-
/* Extended spillbuf initialization. */
117-
static void
118-
init_spillbuf_extended(svn_spillbuf_t *buf,
119-
apr_size_t blocksize,
120-
apr_size_t maxsize,
121-
svn_boolean_t delete_on_close,
122-
svn_boolean_t spill_all_contents,
123-
const char *dirpath,
124-
apr_pool_t *result_pool)
115+
svn_spillbuf_t *
116+
svn_spillbuf__create_extended(apr_size_t blocksize,
117+
apr_size_t maxsize,
118+
unsigned flags,
119+
const char *dirpath,
120+
apr_pool_t *result_pool)
125121
{
122+
svn_spillbuf_t *buf = apr_pcalloc(result_pool, sizeof(*buf));
126123
buf->pool = result_pool;
127124
buf->blocksize = blocksize;
128125
buf->maxsize = maxsize;
129-
buf->delete_on_close = delete_on_close;
130-
buf->spill_all_contents = spill_all_contents;
126+
buf->delete_on_close = 0 != (flags & SVN_SPILLBUF__DELETE_ON_CLOSE);
127+
buf->spill_all_contents = 0 != (flags & SVN_SPILLBUF__SPILL_ALL_CONTENTS);
131128
buf->dirpath = dirpath;
132-
}
133-
134-
/* Common constructor for initializing spillbufs.
135-
Used by svn_spillbuf__create, svn_spilbuff__reader_create. */
136-
static void
137-
init_spillbuf(svn_spillbuf_t *buf,
138-
apr_size_t blocksize,
139-
apr_size_t maxsize,
140-
apr_pool_t *result_pool)
141-
{
142-
init_spillbuf_extended(buf, blocksize, maxsize,
143-
TRUE, FALSE, NULL,
144-
result_pool);
129+
return buf;
145130
}
146131

147132
svn_spillbuf_t *
148133
svn_spillbuf__create(apr_size_t blocksize,
149134
apr_size_t maxsize,
150135
apr_pool_t *result_pool)
151136
{
152-
svn_spillbuf_t *buf = apr_pcalloc(result_pool, sizeof(*buf));
153-
init_spillbuf(buf, blocksize, maxsize, result_pool);
154-
return buf;
155-
}
156-
157-
158-
svn_spillbuf_t *
159-
svn_spillbuf__create_extended(apr_size_t blocksize,
160-
apr_size_t maxsize,
161-
svn_boolean_t delete_on_close,
162-
svn_boolean_t spill_all_contents,
163-
const char *dirpath,
164-
apr_pool_t *result_pool)
165-
{
166-
svn_spillbuf_t *buf = apr_pcalloc(result_pool, sizeof(*buf));
167-
init_spillbuf_extended(buf, blocksize, maxsize,
168-
delete_on_close, spill_all_contents, dirpath,
169-
result_pool);
170-
return buf;
137+
return svn_spillbuf__create_extended(
138+
blocksize, maxsize,
139+
SVN_SPILLBUF__DELETE_ON_CLOSE, /* flags */
140+
NULL, /* dirpath */
141+
result_pool);
171142
}
172143

173144
svn_filesize_t

subversion/tests/libsvn_subr/spillbuf-test.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ test_spillbuf_basic_spill_all(apr_pool_t *pool)
9898
{
9999
apr_size_t len = strlen(basic_data); /* Don't include basic_data's NUL */
100100
svn_spillbuf_t *buf =
101-
svn_spillbuf__create_extended(len, 10 * len, TRUE, TRUE, NULL, pool);
101+
svn_spillbuf__create_extended(len, 10 * len,
102+
SVN_SPILLBUF__DELETE_ON_CLOSE
103+
| SVN_SPILLBUF__SPILL_ALL_CONTENTS,
104+
NULL, pool);
102105
return test_spillbuf__basic(pool, len, buf);
103106
}
104107

@@ -159,8 +162,8 @@ test_spillbuf_callback_spill_all(apr_pool_t *pool)
159162
svn_spillbuf_t *buf = svn_spillbuf__create_extended(
160163
sizeof(basic_data) /* blocksize */,
161164
10 * sizeof(basic_data) /* maxsize */,
162-
TRUE /* delte on close */,
163-
TRUE /* spill all data */,
165+
SVN_SPILLBUF__DELETE_ON_CLOSE
166+
| SVN_SPILLBUF__SPILL_ALL_CONTENTS,
164167
NULL, pool);
165168
return test_spillbuf__callback(pool, buf);
166169
}
@@ -247,8 +250,8 @@ test_spillbuf_file_spill_all(apr_pool_t *pool)
247250
svn_spillbuf_t *buf = svn_spillbuf__create_extended(
248251
altsize /* blocksize */,
249252
2 * sizeof(basic_data) /* maxsize */,
250-
TRUE /* delte on close */,
251-
TRUE /* spill all data */,
253+
SVN_SPILLBUF__DELETE_ON_CLOSE
254+
| SVN_SPILLBUF__SPILL_ALL_CONTENTS,
252255
NULL, pool);
253256
return test_spillbuf__file(pool, altsize, buf);
254257
}
@@ -298,8 +301,8 @@ test_spillbuf_interleaving_spill_all(apr_pool_t *pool)
298301
svn_spillbuf_t *buf = svn_spillbuf__create_extended(
299302
8 /* blocksize */,
300303
15 /* maxsize */,
301-
TRUE /* delte on close */,
302-
TRUE /* spill all data */,
304+
SVN_SPILLBUF__DELETE_ON_CLOSE
305+
| SVN_SPILLBUF__SPILL_ALL_CONTENTS,
303306
NULL, pool);
304307
return test_spillbuf__interleaving(pool, buf);
305308
}
@@ -433,8 +436,8 @@ test_spillbuf_rwfile_spill_all(apr_pool_t *pool)
433436
svn_spillbuf_t *buf = svn_spillbuf__create_extended(
434437
4 /* blocksize */,
435438
10 /* maxsize */,
436-
TRUE /* delte on close */,
437-
TRUE /* spill all data */,
439+
SVN_SPILLBUF__DELETE_ON_CLOSE
440+
| SVN_SPILLBUF__SPILL_ALL_CONTENTS,
438441
NULL, pool);
439442
return test_spillbuf__rwfile(pool, buf);
440443
}
@@ -504,8 +507,8 @@ test_spillbuf_eof_spill_all(apr_pool_t *pool)
504507
svn_spillbuf_t *buf = svn_spillbuf__create_extended(
505508
4 /* blocksize */,
506509
10 /* maxsize */,
507-
TRUE /* delte on close */,
508-
TRUE /* spill all data */,
510+
SVN_SPILLBUF__DELETE_ON_CLOSE
511+
| SVN_SPILLBUF__SPILL_ALL_CONTENTS,
509512
NULL, pool);
510513
return test_spillbuf__eof(pool, buf);
511514
}
@@ -552,8 +555,8 @@ test_spillbuf_file_attrs_spill_all(apr_pool_t *pool)
552555
svn_spillbuf_t *buf = svn_spillbuf__create_extended(
553556
4 /* blocksize */,
554557
10 /* maxsize */,
555-
TRUE /* delte on close */,
556-
TRUE /* spill all data */,
558+
SVN_SPILLBUF__DELETE_ON_CLOSE
559+
| SVN_SPILLBUF__SPILL_ALL_CONTENTS,
557560
NULL, pool);
558561
return test_spillbuf__file_attrs(pool, TRUE, buf);
559562
}

0 commit comments

Comments
 (0)