You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2010/02/16 05:04:50 UTC
svn commit: r910391 - in /lucene/lucy/trunk/core/Lucy:
Store/CompoundFileWriter.c Store/OutStream.bp Store/OutStream.c
Test/Store/TestIOChunks.c
Author: marvin
Date: Tue Feb 16 04:04:50 2010
New Revision: 910391
URL: http://svn.apache.org/viewvc?rev=910391&view=rev
Log:
Add OutStream_Align().
Modified:
lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c
lucene/lucy/trunk/core/Lucy/Store/OutStream.bp
lucene/lucy/trunk/core/Lucy/Store/OutStream.c
lucene/lucy/trunk/core/Lucy/Test/Store/TestIOChunks.c
Modified: lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c?rev=910391&r1=910390&r2=910391&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c (original)
+++ lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c Tue Feb 16 04:04:50 2010
@@ -132,10 +132,7 @@
/* Add filler NULL bytes so that every sub-file begins on a file
* position multiple of 8. */
- {
- i64_t filler_bytes = (8 - (len % 8)) % 8;
- while (filler_bytes--) { OutStream_Write_U8(outstream, 0); }
- }
+ OutStream_Align(outstream, 8);
InStream_Close(instream);
DECREF(instream);
Modified: lucene/lucy/trunk/core/Lucy/Store/OutStream.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/OutStream.bp?rev=910391&r1=910390&r2=910391&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/OutStream.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Store/OutStream.bp Tue Feb 16 04:04:50 2010
@@ -32,6 +32,14 @@
final i64_t
Tell(OutStream *self);
+ /** Write 0 or more null bytes to the OutStream until its file position is
+ * a multiple of <code>modulus</code>.
+ *
+ * @return the new file position.
+ */
+ final i64_t
+ Align(OutStream *self, int64_t modulus);
+
/** Flush output buffer to target FileHandle.
*/
final void
Modified: lucene/lucy/trunk/core/Lucy/Store/OutStream.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/OutStream.c?rev=910391&r1=910390&r2=910391&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/OutStream.c (original)
+++ lucene/lucy/trunk/core/Lucy/Store/OutStream.c Tue Feb 16 04:04:50 2010
@@ -118,6 +118,15 @@
return self->buf_start + self->buf_pos;
}
+int64_t
+OutStream_align(OutStream *self, int64_t modulus)
+{
+ int64_t len = OutStream_Tell(self);
+ int64_t filler_bytes = (modulus - (len % modulus)) % modulus;
+ while (filler_bytes--) { OutStream_Write_U8(self, 0); }
+ return OutStream_Tell(self);
+}
+
void
OutStream_flush(OutStream *self)
{
Modified: lucene/lucy/trunk/core/Lucy/Test/Store/TestIOChunks.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Store/TestIOChunks.c?rev=910391&r1=910390&r2=910391&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Store/TestIOChunks.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Store/TestIOChunks.c Tue Feb 16 04:04:50 2010
@@ -15,6 +15,22 @@
#include "Lucy/Util/NumberUtils.h"
static void
+test_Align(TestBatch *batch)
+{
+ RAMFile *file = RAMFile_new(NULL, false);
+ OutStream *outstream = OutStream_open((Obj*)file);
+
+ for (int32_t i = 1; i < 32; i++) {
+ int64_t random_bytes = TestUtils_random_u64() % 32;
+ while (random_bytes--) { OutStream_Write_U8(outstream, 0); }
+ ASSERT_TRUE(batch, (OutStream_Align(outstream, i) % i) == 0,
+ "Align to %ld", (long)i);
+ }
+ DECREF(file);
+ DECREF(outstream);
+}
+
+static void
test_Read_Write_Bytes(TestBatch *batch)
{
RAMFile *file = RAMFile_new(NULL, false);
@@ -81,11 +97,12 @@
void
TestIOChunks_run_tests()
{
- TestBatch *batch = TestBatch_new(5);
+ TestBatch *batch = TestBatch_new(36);
srand((unsigned int)time((time_t*)NULL));
TestBatch_Plan(batch);
+ test_Align(batch);
test_Read_Write_Bytes(batch);
test_Buf(batch);