You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2013/08/27 00:51:14 UTC
[lucy-commits] [1/7] git commit: refs/heads/cfish-string-prep1 - Change DH_Get_Entry
semantics
Updated Branches:
refs/heads/cfish-string-prep1 4d667ac83 -> f503d90e4
Change DH_Get_Entry semantics
Now DH_Get_Entry must be called after DH_Next and it returns an incref'd
CharBuf. Eliminates a couple of calls to CB_Mimic.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/5ef340d4
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/5ef340d4
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/5ef340d4
Branch: refs/heads/cfish-string-prep1
Commit: 5ef340d4c930a900ba95bf11cf65e8c6b2ddae9e
Parents: 4d667ac
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Aug 26 22:24:22 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 27 00:46:35 2013 +0200
----------------------------------------------------------------------
core/Lucy/Index/FilePurger.c | 16 ++++++-----
core/Lucy/Index/IndexManager.c | 3 +-
core/Lucy/Store/CompoundFileReader.c | 6 ++--
core/Lucy/Store/DirHandle.c | 5 ++--
core/Lucy/Store/DirHandle.cfh | 7 ++---
core/Lucy/Store/FSDirHandle.c | 12 +++++---
core/Lucy/Store/Folder.c | 14 +++++----
core/Lucy/Store/RAMDirHandle.c | 3 +-
core/Lucy/Store/SharedLock.c | 33 ++++++++++------------
core/Lucy/Test/Store/TestCompoundFileReader.c | 7 ++---
core/Lucy/Test/Store/TestFSDirHandle.c | 5 ++--
core/Lucy/Test/Store/TestRAMDirHandle.c | 5 ++--
core/Lucy/Util/IndexFileNames.c | 7 +++--
13 files changed, 68 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Index/FilePurger.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/FilePurger.c b/core/Lucy/Index/FilePurger.c
index ed58fa3..0701bd5 100644
--- a/core/Lucy/Index/FilePurger.c
+++ b/core/Lucy/Index/FilePurger.c
@@ -164,12 +164,13 @@ S_zap_dead_merge(FilePurger *self, Hash *candidates) {
Hash_Store(candidates, (Obj*)cutoff_seg, (Obj*)CFISH_TRUE);
Hash_Store(candidates, (Obj*)merge_json, (Obj*)CFISH_TRUE);
- CharBuf *entry = DH_Get_Entry(dh);
while (DH_Next(dh)) {
// TODO: recursively delete subdirs within seg dir.
+ CharBuf *entry = DH_Get_Entry(dh);
CharBuf *filepath = CB_newf("%o/%o", cutoff_seg, entry);
Hash_Store(candidates, (Obj*)filepath, (Obj*)CFISH_TRUE);
DECREF(filepath);
+ DECREF(entry);
}
DECREF(dh);
}
@@ -205,13 +206,13 @@ S_discover_unused(FilePurger *self, VArray **purgables_ptr,
if (snapfile) { VA_Push(spared, INCREF(snapfile)); }
}
- CharBuf *entry = DH_Get_Entry(dh);
- Hash *candidates = Hash_new(64);
+ Hash *candidates = Hash_new(64);
while (DH_Next(dh)) {
- if (!CB_Starts_With_Str(entry, "snapshot_", 9)) { continue; }
- else if (!CB_Ends_With_Str(entry, ".json", 5)) { continue; }
- else if (snapfile && CB_Equals(entry, (Obj*)snapfile)) { continue; }
- else {
+ CharBuf *entry = DH_Get_Entry(dh);
+ if (CB_Starts_With_Str(entry, "snapshot_", 9)
+ && CB_Ends_With_Str(entry, ".json", 5)
+ && (!snapfile || !CB_Equals(entry, (Obj*)snapfile))
+ ) {
Snapshot *snapshot
= Snapshot_Read_File(Snapshot_new(), folder, entry);
Lock *lock
@@ -249,6 +250,7 @@ S_discover_unused(FilePurger *self, VArray **purgables_ptr,
DECREF(snapshot);
DECREF(lock);
}
+ DECREF(entry);
}
DECREF(dh);
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Index/IndexManager.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/IndexManager.c b/core/Lucy/Index/IndexManager.c
index aa46298..31f9c63 100644
--- a/core/Lucy/Index/IndexManager.c
+++ b/core/Lucy/Index/IndexManager.c
@@ -89,14 +89,15 @@ IxManager_Make_Snapshot_Filename_IMP(IndexManager *self) {
uint64_t max_gen = 0;
if (!dh) { RETHROW(INCREF(Err_get_error())); }
- CharBuf *entry = DH_Get_Entry(dh);
while (DH_Next(dh)) {
+ CharBuf *entry = DH_Get_Entry(dh);
if (CB_Starts_With_Str(entry, "snapshot_", 9)
&& CB_Ends_With_Str(entry, ".json", 5)
) {
uint64_t gen = IxFileNames_extract_gen(entry);
if (gen > max_gen) { max_gen = gen; }
}
+ DECREF(entry);
}
DECREF(dh);
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Store/CompoundFileReader.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/CompoundFileReader.c b/core/Lucy/Store/CompoundFileReader.c
index e76c6d3..cd59e0d 100644
--- a/core/Lucy/Store/CompoundFileReader.c
+++ b/core/Lucy/Store/CompoundFileReader.c
@@ -285,9 +285,10 @@ CFReaderDH_init(CFReaderDirHandle *self, CompoundFileReader *cf_reader) {
// Accumulate entries from real Folder.
Folder *real_folder = CFReader_Get_Real_Folder(ivars->cf_reader);
DirHandle *dh = Folder_Local_Open_Dir(real_folder);
- CharBuf *entry = DH_Get_Entry(dh);
while (DH_Next(dh)) {
+ CharBuf *entry = DH_Get_Entry(dh);
VA_Push(ivars->elems, (Obj*)CB_Clone(entry));
+ DECREF(entry);
}
DECREF(dh);
return self;
@@ -315,7 +316,8 @@ CFReaderDH_Next_IMP(CFReaderDirHandle *self) {
if (ivars->tick < (int32_t)VA_Get_Size(ivars->elems)) {
CharBuf *path = (CharBuf*)CERTIFY(
VA_Fetch(ivars->elems, ivars->tick), CHARBUF);
- CB_Mimic(ivars->entry, (Obj*)path);
+ DECREF(ivars->entry);
+ ivars->entry = (CharBuf*)INCREF(path);
return true;
}
else {
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Store/DirHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/DirHandle.c b/core/Lucy/Store/DirHandle.c
index a7bd0da..9d5f3a4 100644
--- a/core/Lucy/Store/DirHandle.c
+++ b/core/Lucy/Store/DirHandle.c
@@ -22,7 +22,7 @@ DirHandle*
DH_init(DirHandle *self, const CharBuf *dir) {
DirHandleIVARS *const ivars = DH_IVARS(self);
ivars->dir = CB_Clone(dir);
- ivars->entry = CB_new(32);
+ ivars->entry = NULL;
ABSTRACT_CLASS_CHECK(self, DIRHANDLE);
return self;
}
@@ -43,7 +43,8 @@ DH_Get_Dir_IMP(DirHandle *self) {
CharBuf*
DH_Get_Entry_IMP(DirHandle *self) {
- return DH_IVARS(self)->entry;
+ CharBuf *entry = DH_IVARS(self)->entry;
+ return (CharBuf*)INCREF(entry);
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Store/DirHandle.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/DirHandle.cfh b/core/Lucy/Store/DirHandle.cfh
index fc26f63..f776b93 100644
--- a/core/Lucy/Store/DirHandle.cfh
+++ b/core/Lucy/Store/DirHandle.cfh
@@ -49,11 +49,10 @@ abstract class Lucy::Store::DirHandle cnick DH
CharBuf*
Get_Dir(DirHandle *self);
- /** Return the path of the current entry. The value is updated by each
- * call to Next(), and is only valid when Next() has returned
- * successfully.
+ /** Return the path of the current entry. The value is only valid when
+ * Next() has returned successfully.
*/
- CharBuf*
+ incremented CharBuf*
Get_Entry(DirHandle *self);
/** Returns true if the current entry is a directory, false otherwise.
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Store/FSDirHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FSDirHandle.c b/core/Lucy/Store/FSDirHandle.c
index 11ac83b..369d118 100644
--- a/core/Lucy/Store/FSDirHandle.c
+++ b/core/Lucy/Store/FSDirHandle.c
@@ -177,7 +177,8 @@ FSDH_Next_IMP(FSDirHandle *self) {
}
else if ((FindNextFile(dirhandle, find_data) == 0)) {
// Iterator exhausted. Verify that no errors were encountered.
- CB_Set_Size(ivars->entry, 0);
+ DECREF(ivars->entry);
+ ivars->entry = NULL;
if (GetLastError() != ERROR_NO_MORE_FILES) {
char *win_error = Err_win_error();
ivars->saved_error
@@ -194,7 +195,8 @@ FSDH_Next_IMP(FSDirHandle *self) {
return FSDH_Next(self);
}
else {
- CB_Mimic_Str(ivars->entry, find_data->cFileName, len);
+ DECREF(ivars->entry);
+ ivars->entry = CB_new_from_utf8(find_data->cFileName, len);
return true;
}
}
@@ -228,7 +230,8 @@ FSDH_Next_IMP(FSDirHandle *self) {
FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
ivars->sys_dir_entry = (struct dirent*)readdir((DIR*)ivars->sys_dirhandle);
if (!ivars->sys_dir_entry) {
- CB_Set_Size(ivars->entry, 0);
+ DECREF(ivars->entry);
+ ivars->entry = NULL;
return false;
}
else {
@@ -242,7 +245,8 @@ FSDH_Next_IMP(FSDirHandle *self) {
return FSDH_Next(self);
}
else {
- CB_Mimic_Str(ivars->entry, sys_dir_entry->d_name, len);
+ DECREF(ivars->entry);
+ ivars->entry = CB_new_from_utf8(sys_dir_entry->d_name, len);
return true;
}
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Store/Folder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/Folder.c b/core/Lucy/Store/Folder.c
index 265eadb..b9a7d39 100644
--- a/core/Lucy/Store/Folder.c
+++ b/core/Lucy/Store/Folder.c
@@ -168,12 +168,13 @@ Folder_Delete_Tree_IMP(Folder *self, const CharBuf *path) {
if (dh) {
VArray *files = VA_new(20);
VArray *dirs = VA_new(20);
- CharBuf *entry = DH_Get_Entry(dh);
while (DH_Next(dh)) {
+ CharBuf *entry = DH_Get_Entry(dh);
VA_Push(files, (Obj*)CB_Clone(entry));
if (DH_Entry_Is_Dir(dh) && !DH_Entry_Is_Symlink(dh)) {
VA_Push(dirs, (Obj*)CB_Clone(entry));
}
+ DECREF(entry);
}
for (uint32_t i = 0, max = VA_Get_Size(dirs); i < max; i++) {
CharBuf *name = (CharBuf*)VA_Fetch(files, i);
@@ -216,14 +217,13 @@ static void
S_add_to_file_list(Folder *self, VArray *list, CharBuf *dir,
const CharBuf *path) {
DirHandle *dh = Folder_Open_Dir(self, dir);
- CharBuf *entry;
if (!dh) {
RETHROW(INCREF(Err_get_error()));
}
- entry = DH_Get_Entry(dh);
while (DH_Next(dh)) { // Updates entry
+ CharBuf *entry = DH_Get_Entry(dh);
if (!S_is_updir(entry)) {
CharBuf *relpath = path && CB_Get_Size(path)
? CB_newf("%o/%o", path, entry)
@@ -241,6 +241,7 @@ S_add_to_file_list(Folder *self, VArray *list, CharBuf *dir,
DECREF(subdir);
}
}
+ DECREF(entry);
}
if (!DH_Close(dh)) {
@@ -327,9 +328,12 @@ Folder_List_IMP(Folder *self, const CharBuf *path) {
VArray *list = NULL;
DirHandle *dh = Folder_Local_Open_Dir(local_folder);
if (dh) {
- CharBuf *entry = DH_Get_Entry(dh);
list = VA_new(32);
- while (DH_Next(dh)) { VA_Push(list, (Obj*)CB_Clone(entry)); }
+ while (DH_Next(dh)) {
+ CharBuf *entry = DH_Get_Entry(dh);
+ VA_Push(list, (Obj*)CB_Clone(entry));
+ DECREF(entry);
+ }
DECREF(dh);
}
else {
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Store/RAMDirHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/RAMDirHandle.c b/core/Lucy/Store/RAMDirHandle.c
index ef66cbc..4900a69 100644
--- a/core/Lucy/Store/RAMDirHandle.c
+++ b/core/Lucy/Store/RAMDirHandle.c
@@ -60,7 +60,8 @@ RAMDH_Next_IMP(RAMDirHandle *self) {
if (ivars->tick < (int32_t)VA_Get_Size(ivars->elems)) {
CharBuf *path = (CharBuf*)CERTIFY(
VA_Fetch(ivars->elems, ivars->tick), CHARBUF);
- CB_Mimic(ivars->entry, (Obj*)path);
+ DECREF(ivars->entry);
+ ivars->entry = (CharBuf*)INCREF(path);
return true;
}
else {
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Store/SharedLock.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/SharedLock.c b/core/Lucy/Store/SharedLock.c
index 2ec1226..a6083b3 100644
--- a/core/Lucy/Store/SharedLock.c
+++ b/core/Lucy/Store/SharedLock.c
@@ -98,21 +98,18 @@ ShLock_Release_IMP(SharedLock *self) {
void
ShLock_Clear_Stale_IMP(SharedLock *self) {
SharedLockIVARS *const ivars = ShLock_IVARS(self);
- DirHandle *dh;
- CharBuf *entry;
- CharBuf *lock_dir_name = (CharBuf*)ZCB_WRAP_STR("locks", 5);
-
- if (Folder_Find_Folder(ivars->folder, lock_dir_name)) {
- dh = Folder_Open_Dir(ivars->folder, lock_dir_name);
- if (!dh) { RETHROW(INCREF(Err_get_error())); }
- entry = DH_Get_Entry(dh);
- }
- else {
+
+ CharBuf *lock_dir_name = (CharBuf*)ZCB_WRAP_STR("locks", 5);
+ if (!Folder_Find_Folder(ivars->folder, lock_dir_name)) {
return;
}
+ DirHandle *dh = Folder_Open_Dir(ivars->folder, lock_dir_name);
+ if (!dh) { RETHROW(INCREF(Err_get_error())); }
+
// Take a stab at any file that begins with our lock name.
while (DH_Next(dh)) {
+ CharBuf *entry = DH_Get_Entry(dh);
if (CB_Starts_With(entry, ivars->name)
&& CB_Ends_With_Str(entry, ".lock", 5)
) {
@@ -120,6 +117,7 @@ ShLock_Clear_Stale_IMP(SharedLock *self) {
ShLock_Maybe_Delete_File(self, candidate, false, true);
DECREF(candidate);
}
+ DECREF(entry);
}
DECREF(dh);
@@ -128,20 +126,17 @@ ShLock_Clear_Stale_IMP(SharedLock *self) {
bool
ShLock_Is_Locked_IMP(SharedLock *self) {
SharedLockIVARS *const ivars = ShLock_IVARS(self);
- DirHandle *dh;
- CharBuf *entry;
CharBuf *lock_dir_name = (CharBuf*)ZCB_WRAP_STR("locks", 5);
- if (Folder_Find_Folder(ivars->folder, lock_dir_name)) {
- dh = Folder_Open_Dir(ivars->folder, lock_dir_name);
- if (!dh) { RETHROW(INCREF(Err_get_error())); }
- entry = DH_Get_Entry(dh);
- }
- else {
+ if (!Folder_Find_Folder(ivars->folder, lock_dir_name)) {
return false;
}
+ DirHandle *dh = Folder_Open_Dir(ivars->folder, lock_dir_name);
+ if (!dh) { RETHROW(INCREF(Err_get_error())); }
+
while (DH_Next(dh)) {
+ CharBuf *entry = DH_Get_Entry(dh);
// Translation: $locked = 1 if $entry =~ /^\Q$name-\d+\.lock$/
if (CB_Starts_With(entry, ivars->name)
&& CB_Ends_With_Str(entry, ".lock", 5)
@@ -154,11 +149,13 @@ ShLock_Is_Locked_IMP(SharedLock *self) {
if (ZCB_Code_Point_From(scratch, 1) == '-') {
ZCB_Chop(scratch, 1);
if (ZCB_Equals(scratch, (Obj*)ivars->name)) {
+ DECREF(entry);
DECREF(dh);
return true;
}
}
}
+ DECREF(entry);
}
DECREF(dh);
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Test/Store/TestCompoundFileReader.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Store/TestCompoundFileReader.c b/core/Lucy/Test/Store/TestCompoundFileReader.c
index 7e7f055..1e0de34 100644
--- a/core/Lucy/Test/Store/TestCompoundFileReader.c
+++ b/core/Lucy/Test/Store/TestCompoundFileReader.c
@@ -243,17 +243,15 @@ test_Local_Open_Dir(TestBatchRunner *runner) {
Folder *real_folder = S_folder_with_contents();
CompoundFileReader *cf_reader = CFReader_open(real_folder);
- DirHandle *dh;
- CharBuf *entry;
bool saw_foo = false;
bool saw_stuff = false;
bool stuff_was_dir = false;
CFReader_MkDir(cf_reader, stuff);
- dh = CFReader_Local_Open_Dir(cf_reader);
- entry = DH_Get_Entry(dh);
+ DirHandle *dh = CFReader_Local_Open_Dir(cf_reader);
while (DH_Next(dh)) {
+ CharBuf *entry = DH_Get_Entry(dh);
if (CB_Equals(entry, (Obj*)foo)) {
saw_foo = true;
}
@@ -261,6 +259,7 @@ test_Local_Open_Dir(TestBatchRunner *runner) {
saw_stuff = true;
stuff_was_dir = DH_Entry_Is_Dir(dh);
}
+ DECREF(entry);
}
TEST_TRUE(runner, saw_foo, "DirHandle iterated over virtual file");
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Test/Store/TestFSDirHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Store/TestFSDirHandle.c b/core/Lucy/Test/Store/TestFSDirHandle.c
index 0254569..93ef324 100644
--- a/core/Lucy/Test/Store/TestFSDirHandle.c
+++ b/core/Lucy/Test/Store/TestFSDirHandle.c
@@ -65,10 +65,10 @@ test_all(TestBatchRunner *runner) {
outstream = FSFolder_Open_Out(folder, foo_boffo);
DECREF(outstream);
- FSDirHandle *dh = FSDH_open(test_dir);
- CharBuf *entry = FSDH_Get_Entry(dh);
+ FSDirHandle *dh = FSDH_open(test_dir);
while (FSDH_Next(dh)) {
count++;
+ CharBuf *entry = FSDH_Get_Entry(dh);
if (CB_Equals(entry, (Obj*)foo)) {
saw_foo = true;
foo_was_dir = FSDH_Entry_Is_Dir(dh);
@@ -77,6 +77,7 @@ test_all(TestBatchRunner *runner) {
saw_boffo = true;
boffo_was_dir = FSDH_Entry_Is_Dir(dh);
}
+ DECREF(entry);
}
TEST_INT_EQ(runner, 2, count, "correct number of entries");
TEST_TRUE(runner, saw_foo, "Directory was iterated over");
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Test/Store/TestRAMDirHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Store/TestRAMDirHandle.c b/core/Lucy/Test/Store/TestRAMDirHandle.c
index d29b457..70953d9 100644
--- a/core/Lucy/Test/Store/TestRAMDirHandle.c
+++ b/core/Lucy/Test/Store/TestRAMDirHandle.c
@@ -51,10 +51,10 @@ test_all(TestBatchRunner *runner) {
FH_CREATE | FH_WRITE_ONLY);
DECREF(fh);
- RAMDirHandle *dh = RAMDH_new(folder);
- CharBuf *entry = RAMDH_Get_Entry(dh);
+ RAMDirHandle *dh = RAMDH_new(folder);
while (RAMDH_Next(dh)) {
count++;
+ CharBuf *entry = RAMDH_Get_Entry(dh);
if (CB_Equals(entry, (Obj*)foo)) {
saw_foo = true;
foo_was_dir = RAMDH_Entry_Is_Dir(dh);
@@ -63,6 +63,7 @@ test_all(TestBatchRunner *runner) {
saw_boffo = true;
boffo_was_dir = RAMDH_Entry_Is_Dir(dh);
}
+ DECREF(entry);
}
TEST_INT_EQ(runner, 2, count, "correct number of entries");
TEST_TRUE(runner, saw_foo, "Directory was iterated over");
http://git-wip-us.apache.org/repos/asf/lucy/blob/5ef340d4/core/Lucy/Util/IndexFileNames.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/IndexFileNames.c b/core/Lucy/Util/IndexFileNames.c
index 72229b6..e4d2872 100644
--- a/core/Lucy/Util/IndexFileNames.c
+++ b/core/Lucy/Util/IndexFileNames.c
@@ -25,23 +25,24 @@
CharBuf*
IxFileNames_latest_snapshot(Folder *folder) {
DirHandle *dh = Folder_Open_Dir(folder, NULL);
- CharBuf *entry = dh ? DH_Get_Entry(dh) : NULL;
CharBuf *retval = NULL;
uint64_t latest_gen = 0;
if (!dh) { RETHROW(INCREF(Err_get_error())); }
while (DH_Next(dh)) {
+ CharBuf *entry = DH_Get_Entry(dh);
if (CB_Starts_With_Str(entry, "snapshot_", 9)
&& CB_Ends_With_Str(entry, ".json", 5)
) {
uint64_t gen = IxFileNames_extract_gen(entry);
if (gen > latest_gen) {
latest_gen = gen;
- if (!retval) { retval = CB_Clone(entry); }
- else { CB_Mimic(retval, (Obj*)entry); }
+ DECREF(retval);
+ retval = CB_Clone(entry);
}
}
+ DECREF(entry);
}
DECREF(dh);
[lucy-commits] [5/7] git commit: refs/heads/cfish-string-prep1 - Simplify
S_do_consolidate in CompoundFileWriter
Posted by nw...@apache.org.
Simplify S_do_consolidate in CompoundFileWriter
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/1a8ccea8
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/1a8ccea8
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/1a8ccea8
Branch: refs/heads/cfish-string-prep1
Commit: 1a8ccea84fa62444f635badc01562b518e2ca923
Parents: 5169be5
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Aug 26 22:58:59 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 27 00:46:55 2013 +0200
----------------------------------------------------------------------
core/Lucy/Store/CompoundFileWriter.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/1a8ccea8/core/Lucy/Store/CompoundFileWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/CompoundFileWriter.c b/core/Lucy/Store/CompoundFileWriter.c
index 89ed2c2..0337605 100644
--- a/core/Lucy/Store/CompoundFileWriter.c
+++ b/core/Lucy/Store/CompoundFileWriter.c
@@ -109,8 +109,6 @@ S_do_consolidate(CompoundFileWriter *self, CompoundFileWriterIVARS *ivars) {
Hash_Store_Str(metadata, "format", 6,
(Obj*)CB_newf("%i32", CFWriter_current_file_format));
- CharBuf *infilepath = CB_new(30);
- size_t base_len = 0;
VA_Sort(files, NULL, NULL);
for (uint32_t i = 0, max = VA_Get_Size(files); i < max; i++) {
CharBuf *infilename = (CharBuf*)VA_Fetch(files, i);
@@ -132,9 +130,7 @@ S_do_consolidate(CompoundFileWriter *self, CompoundFileWriterIVARS *ivars) {
(Obj*)CB_newf("%i64", offset));
Hash_Store_Str(file_data, "length", 6,
(Obj*)CB_newf("%i64", len));
- CB_Set_Size(infilepath, base_len);
- CB_Cat(infilepath, infilename);
- Hash_Store(sub_files, (Obj*)infilepath, (Obj*)file_data);
+ Hash_Store(sub_files, (Obj*)infilename, (Obj*)file_data);
VA_Push(merged, INCREF(infilename));
// Add filler NULL bytes so that every sub-file begins on a file
@@ -145,7 +141,6 @@ S_do_consolidate(CompoundFileWriter *self, CompoundFileWriterIVARS *ivars) {
DECREF(instream);
}
}
- DECREF(infilepath);
// Write metadata to cfmeta file.
CharBuf *cfmeta_temp = (CharBuf*)ZCB_WRAP_STR("cfmeta.json.temp", 16);
[lucy-commits] [7/7] git commit: refs/heads/cfish-string-prep1 - Switch to
ViewCB_Nibble in CB_Hash_Sum
Posted by nw...@apache.org.
Switch to ViewCB_Nibble in CB_Hash_Sum
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/657557a0
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/657557a0
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/657557a0
Branch: refs/heads/cfish-string-prep1
Commit: 657557a0f726657e25102c12cb94058cbe4dc1d9
Parents: 1a8ccea
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Aug 26 23:04:05 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 27 00:46:55 2013 +0200
----------------------------------------------------------------------
clownfish/runtime/core/Clownfish/CharBuf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/657557a0/clownfish/runtime/core/Clownfish/CharBuf.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/CharBuf.c b/clownfish/runtime/core/Clownfish/CharBuf.c
index c26c25a..271039d 100644
--- a/clownfish/runtime/core/Clownfish/CharBuf.c
+++ b/clownfish/runtime/core/Clownfish/CharBuf.c
@@ -138,9 +138,10 @@ CB_Hash_Sum_IMP(CharBuf *self) {
uint32_t hashvalue = 5381;
ZombieCharBuf *iterator = ZCB_WRAP(self);
- const CB_Nibble_t nibble = METHOD_PTR(iterator->vtable, CFISH_CB_Nibble);
+ const ViewCB_Nibble_t nibble = METHOD_PTR(iterator->vtable,
+ CFISH_ViewCB_Nibble);
while (iterator->size) {
- uint32_t code_point = (uint32_t)nibble((CharBuf*)iterator);
+ uint32_t code_point = (uint32_t)nibble((ViewCharBuf*)iterator);
hashvalue = ((hashvalue << 5) + hashvalue) ^ code_point;
}
[lucy-commits] [6/7] git commit: refs/heads/cfish-string-prep1 - Remove CB_setf
Posted by nw...@apache.org.
Remove CB_setf
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/467cffb1
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/467cffb1
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/467cffb1
Branch: refs/heads/cfish-string-prep1
Commit: 467cffb1f1fd4f5b646e2674451257c123876003
Parents: 85a4a57
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Aug 26 23:30:51 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 27 00:46:55 2013 +0200
----------------------------------------------------------------------
clownfish/runtime/core/Clownfish/CharBuf.c | 9 -----
clownfish/runtime/core/Clownfish/CharBuf.cfh | 5 ---
.../runtime/core/Clownfish/Test/TestCharBuf.c | 36 ++++++++++++++------
3 files changed, 25 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/467cffb1/clownfish/runtime/core/Clownfish/CharBuf.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/CharBuf.c b/clownfish/runtime/core/Clownfish/CharBuf.c
index 249530e..356bf76 100644
--- a/clownfish/runtime/core/Clownfish/CharBuf.c
+++ b/clownfish/runtime/core/Clownfish/CharBuf.c
@@ -184,15 +184,6 @@ S_die_invalid_pattern(const char *pattern) {
}
void
-CB_setf(CharBuf *self, const char *pattern, ...) {
- va_list args;
- CB_Set_Size(self, 0);
- va_start(args, pattern);
- CB_VCatF(self, pattern, args);
- va_end(args);
-}
-
-void
CB_catf(CharBuf *self, const char *pattern, ...) {
va_list args;
va_start(args, pattern);
http://git-wip-us.apache.org/repos/asf/lucy/blob/467cffb1/clownfish/runtime/core/Clownfish/CharBuf.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/CharBuf.cfh b/clownfish/runtime/core/Clownfish/CharBuf.cfh
index 37cf73f..1832df7 100644
--- a/clownfish/runtime/core/Clownfish/CharBuf.cfh
+++ b/clownfish/runtime/core/Clownfish/CharBuf.cfh
@@ -124,11 +124,6 @@ class Clownfish::CharBuf cnick CB
inert void
catf(CharBuf *self, const char *pattern, ...);
- /** Replaces the contents of the CharBuf using formatted arguments.
- */
- inert void
- setf(CharBuf *self, const char *pattern, ...);
-
/** Concatenate one Unicode character onto the end of the CharBuf.
*/
void
http://git-wip-us.apache.org/repos/asf/lucy/blob/467cffb1/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c b/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c
index 1d7393f..572c466 100644
--- a/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c
+++ b/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c
@@ -95,21 +95,28 @@ test_Mimic_and_Clone(TestBatchRunner *runner) {
static void
test_Find(TestBatchRunner *runner) {
- CharBuf *string = CB_new(10);
+ CharBuf *string;
CharBuf *substring = S_get_cb("foo");
+ string = S_get_cb("");
TEST_TRUE(runner, CB_Find(string, substring) == -1, "Not in empty string");
- CB_setf(string, "foo");
+ DECREF(string);
+
+ string = S_get_cb("foo");
TEST_TRUE(runner, CB_Find(string, substring) == 0, "Find complete string");
- CB_setf(string, "afoo");
+ DECREF(string);
+
+ string = S_get_cb("afoo");
TEST_TRUE(runner, CB_Find(string, substring) == 1, "Find after first");
CB_Set_Size(string, 3);
TEST_TRUE(runner, CB_Find(string, substring) == -1, "Don't overrun");
- CB_setf(string, "afood");
+ DECREF(string);
+
+ string = S_get_cb("afood");
TEST_TRUE(runner, CB_Find(string, substring) == 1, "Find in middle");
+ DECREF(string);
DECREF(substring);
- DECREF(string);
}
static void
@@ -217,31 +224,38 @@ test_Trim(TestBatchRunner *runner) {
static void
test_To_F64(TestBatchRunner *runner) {
- CharBuf *charbuf = S_get_cb("1.5");
+ CharBuf *charbuf;
+
+ charbuf = S_get_cb("1.5");
double difference = 1.5 - CB_To_F64(charbuf);
if (difference < 0) { difference = 0 - difference; }
TEST_TRUE(runner, difference < 0.001, "To_F64");
+ DECREF(charbuf);
- CB_setf(charbuf, "-1.5");
+ charbuf = S_get_cb("-1.5");
difference = 1.5 + CB_To_F64(charbuf);
if (difference < 0) { difference = 0 - difference; }
TEST_TRUE(runner, difference < 0.001, "To_F64 negative");
+ DECREF(charbuf);
- CB_setf(charbuf, "1.59");
+ charbuf = S_get_cb("1.59");
double value_full = CB_To_F64(charbuf);
CB_Set_Size(charbuf, 3);
double value_short = CB_To_F64(charbuf);
TEST_TRUE(runner, value_short < value_full,
"TO_F64 doesn't run past end of string");
-
DECREF(charbuf);
}
static void
test_To_I64(TestBatchRunner *runner) {
- CharBuf *charbuf = S_get_cb("10");
+ CharBuf *charbuf;
+
+ charbuf = S_get_cb("10");
TEST_TRUE(runner, CB_To_I64(charbuf) == 10, "To_I64");
- CB_setf(charbuf, "-10");
+ DECREF(charbuf);
+
+ charbuf = S_get_cb("-10");
TEST_TRUE(runner, CB_To_I64(charbuf) == -10, "To_I64 negative");
DECREF(charbuf);
}
[lucy-commits] [2/7] git commit: refs/heads/cfish-string-prep1 - Use CB_newf in
SkipStepper_To_String
Posted by nw...@apache.org.
Use CB_newf in SkipStepper_To_String
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/f503d90e
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/f503d90e
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/f503d90e
Branch: refs/heads/cfish-string-prep1
Commit: f503d90e4b35f19f3f4765db4119c235fa8c9243
Parents: 467cffb
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Aug 27 00:45:47 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 27 00:46:55 2013 +0200
----------------------------------------------------------------------
core/Lucy/Index/SkipStepper.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/f503d90e/core/Lucy/Index/SkipStepper.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SkipStepper.c b/core/Lucy/Index/SkipStepper.c
index c0a5246..e92e23c 100644
--- a/core/Lucy/Index/SkipStepper.c
+++ b/core/Lucy/Index/SkipStepper.c
@@ -54,10 +54,8 @@ SkipStepper_Read_Record_IMP(SkipStepper *self, InStream *instream) {
CharBuf*
SkipStepper_To_String_IMP(SkipStepper *self) {
SkipStepperIVARS *const ivars = SkipStepper_IVARS(self);
- char *ptr = (char*)MALLOCATE(60);
- size_t len = sprintf(ptr, "skip doc: %u file pointer: %" PRId64,
- ivars->doc_id, ivars->filepos);
- return CB_new_steal_from_trusted_str(ptr, len, 60);
+ return CB_newf("skip doc: %u32 file pointer: %i64", ivars->doc_id,
+ ivars->filepos);
}
void
[lucy-commits] [4/7] git commit: refs/heads/cfish-string-prep1 - Move Nip, Nibble,
and Chop from CharBuf to ViewCharBuf
Posted by nw...@apache.org.
Move Nip, Nibble, and Chop from CharBuf to ViewCharBuf
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/85a4a575
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/85a4a575
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/85a4a575
Branch: refs/heads/cfish-string-prep1
Commit: 85a4a575be6f89c099cb2f5851a5399107d95e93
Parents: 657557a
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Aug 26 23:12:45 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 27 00:46:55 2013 +0200
----------------------------------------------------------------------
clownfish/runtime/core/Clownfish/CharBuf.c | 60 +++++---------------
clownfish/runtime/core/Clownfish/CharBuf.cfh | 30 ++++------
.../runtime/core/Clownfish/Test/TestCharBuf.c | 17 +++---
3 files changed, 35 insertions(+), 72 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/85a4a575/clownfish/runtime/core/Clownfish/CharBuf.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/CharBuf.c b/clownfish/runtime/core/Clownfish/CharBuf.c
index 271039d..249530e 100644
--- a/clownfish/runtime/core/Clownfish/CharBuf.c
+++ b/clownfish/runtime/core/Clownfish/CharBuf.c
@@ -626,53 +626,6 @@ CB_Trim_Tail_IMP(CharBuf *self) {
}
size_t
-CB_Nip_IMP(CharBuf *self, size_t count) {
- size_t num_nipped = 0;
- char *ptr = self->ptr;
- char *const end = ptr + self->size;
- for (; ptr < end && count--; ptr += StrHelp_UTF8_COUNT[*(uint8_t*)ptr]) {
- num_nipped++;
- }
- if (ptr > end) {
- DIE_INVALID_UTF8(self->ptr, self->size);
- }
- self->size = end - ptr;
- memmove(self->ptr, ptr, self->size);
- return num_nipped;
-}
-
-int32_t
-CB_Nibble_IMP(CharBuf *self) {
- if (self->size == 0) {
- return 0;
- }
- else {
- int32_t retval = (int32_t)StrHelp_decode_utf8_char(self->ptr);
- size_t consumed = StrHelp_UTF8_COUNT[*(uint8_t*)self->ptr];
- if (consumed > self->size) {
- DIE_INVALID_UTF8(self->ptr, self->size);
- }
- char *ptr = self->ptr + StrHelp_UTF8_COUNT[*(uint8_t*)self->ptr];
- self->size -= consumed;
- memmove(self->ptr, ptr, self->size);
- return retval;
- }
-}
-
-size_t
-CB_Chop_IMP(CharBuf *self, size_t count) {
- size_t num_chopped = 0;
- char *top = self->ptr;
- const char *ptr = top + self->size;
- for (num_chopped = 0; num_chopped < count; num_chopped++) {
- const char *end = ptr;
- if (NULL == (ptr = StrHelp_back_utf8_char(ptr, top))) { break; }
- self->size -= (end - ptr);
- }
- return num_chopped;
-}
-
-size_t
CB_Length_IMP(CharBuf *self) {
size_t len = 0;
char *ptr = self->ptr;
@@ -891,6 +844,19 @@ ViewCB_Nibble_IMP(ViewCharBuf *self) {
}
}
+size_t
+ViewCB_Chop_IMP(ViewCharBuf *self, size_t count) {
+ size_t num_chopped = 0;
+ char *top = self->ptr;
+ const char *ptr = top + self->size;
+ for (num_chopped = 0; num_chopped < count; num_chopped++) {
+ const char *end = ptr;
+ if (NULL == (ptr = StrHelp_back_utf8_char(ptr, top))) { break; }
+ self->size -= (end - ptr);
+ }
+ return num_chopped;
+}
+
char*
ViewCB_Grow_IMP(ViewCharBuf *self, size_t size) {
UNUSED_VAR(size);
http://git-wip-us.apache.org/repos/asf/lucy/blob/85a4a575/clownfish/runtime/core/Clownfish/CharBuf.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/CharBuf.cfh b/clownfish/runtime/core/Clownfish/CharBuf.cfh
index 12fcf6d..37cf73f 100644
--- a/clownfish/runtime/core/Clownfish/CharBuf.cfh
+++ b/clownfish/runtime/core/Clownfish/CharBuf.cfh
@@ -254,24 +254,6 @@ class Clownfish::CharBuf cnick CB
uint32_t
Trim_Tail(CharBuf *self);
- /** Remove characters (measured in code points) from the top of the
- * CharBuf. Returns the number nipped.
- */
- size_t
- Nip(CharBuf *self, size_t count);
-
- /** Remove one character from the top of the CharBuf. Returns the code
- * point, or 0 if the string was empty.
- */
- int32_t
- Nibble(CharBuf *self);
-
- /** Remove characters (measured in code points) from the end of the
- * CharBuf. Returns the number chopped.
- */
- size_t
- Chop(CharBuf *self, size_t count);
-
/** Truncate the CharBuf so that it contains no more than
* <code>count</code>characters.
*
@@ -335,12 +317,24 @@ class Clownfish::ViewCharBuf cnick ViewCB
uint32_t
Trim_Top(ViewCharBuf *self);
+ /** Remove characters (measured in code points) from the top of the
+ * ViewCharBuf. Returns the number nipped.
+ */
size_t
Nip(ViewCharBuf *self, size_t count);
+ /** Remove one character from the top of the ViewCharBuf. Returns the
+ * code point, or 0 if the string was empty.
+ */
int32_t
Nibble(ViewCharBuf *self);
+ /** Remove characters (measured in code points) from the end of the
+ * ViewCharBuf. Returns the number chopped.
+ */
+ size_t
+ Chop(ViewCharBuf *self, size_t count);
+
/** Throws an error. */
char*
Grow(ViewCharBuf *self, size_t size);
http://git-wip-us.apache.org/repos/asf/lucy/blob/85a4a575/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c b/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c
index 63836d6..1d7393f 100644
--- a/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c
+++ b/clownfish/runtime/core/Clownfish/Test/TestCharBuf.c
@@ -144,21 +144,24 @@ test_SubString(TestBatchRunner *runner) {
static void
test_Nip_and_Chop(TestBatchRunner *runner) {
CharBuf *wanted;
- CharBuf *got;
+ CharBuf *string;
+ ZombieCharBuf *got;
wanted = CB_newf("%sb%sc", smiley, smiley);
- got = CB_newf("a%s%sb%sc", smiley, smiley, smiley);
- CB_Nip(got, 2);
+ string = CB_newf("a%s%sb%sc", smiley, smiley, smiley);
+ got = ZCB_WRAP(string);
+ ZCB_Nip(got, 2);
TEST_TRUE(runner, CB_Equals(wanted, (Obj*)got), "Nip");
DECREF(wanted);
- DECREF(got);
+ DECREF(string);
wanted = CB_newf("a%s%s", smiley, smiley);
- got = CB_newf("a%s%sb%sc", smiley, smiley, smiley);
- CB_Chop(got, 3);
+ string = CB_newf("a%s%sb%sc", smiley, smiley, smiley);
+ got = ZCB_WRAP(string);
+ ZCB_Chop(got, 3);
TEST_TRUE(runner, CB_Equals(wanted, (Obj*)got), "Chop");
DECREF(wanted);
- DECREF(got);
+ DECREF(string);
}
[lucy-commits] [3/7] git commit: refs/heads/cfish-string-prep1 - Eliminate CB_setf
in FSDirHandle
Posted by nw...@apache.org.
Eliminate CB_setf in FSDirHandle
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/5169be5e
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/5169be5e
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/5169be5e
Branch: refs/heads/cfish-string-prep1
Commit: 5169be5efa3c05255a3604eb92fdbda4c1b27b3b
Parents: 5ef340d
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Aug 26 22:33:47 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 27 00:46:55 2013 +0200
----------------------------------------------------------------------
core/Lucy/Store/FSDirHandle.c | 37 +++++++++++++++---------------------
core/Lucy/Store/FSDirHandle.cfh | 1 -
2 files changed, 15 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/5169be5e/core/Lucy/Store/FSDirHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FSDirHandle.c b/core/Lucy/Store/FSDirHandle.c
index 369d118..abc92cc 100644
--- a/core/Lucy/Store/FSDirHandle.c
+++ b/core/Lucy/Store/FSDirHandle.c
@@ -212,8 +212,7 @@ FSDH_do_open(FSDirHandle *self, const CharBuf *dir) {
DH_init((DirHandle*)self, dir);
FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
- ivars->sys_dir_entry = NULL;
- ivars->fullpath = NULL;
+ ivars->sys_dir_entry = NULL;
ivars->sys_dirhandle = opendir(dir_path_ptr);
if (!ivars->sys_dirhandle) {
@@ -269,16 +268,15 @@ FSDH_Entry_Is_Dir_IMP(FSDirHandle *self) {
}
#endif
+ bool retval = false;
struct stat stat_buf;
- if (!ivars->fullpath) {
- ivars->fullpath = CB_new(CB_Get_Size(ivars->dir) + 20);
+ CharBuf *fullpath = CB_newf("%o%s%o", ivars->dir, CHY_DIR_SEP,
+ ivars->entry);
+ if (stat((char*)CB_Get_Ptr8(fullpath), &stat_buf) != -1) {
+ if (stat_buf.st_mode & S_IFDIR) { retval = true; }
}
- CB_setf(ivars->fullpath, "%o%s%o", ivars->dir, CHY_DIR_SEP,
- ivars->entry);
- if (stat((char*)CB_Get_Ptr8(ivars->fullpath), &stat_buf) != -1) {
- if (stat_buf.st_mode & S_IFDIR) { return true; }
- }
- return false;
+ DECREF(fullpath);
+ return retval;
}
bool
@@ -291,16 +289,15 @@ FSDH_Entry_Is_Symlink_IMP(FSDirHandle *self) {
return sys_dir_entry->d_type == DT_LNK ? true : false;
#else
{
+ bool retval = false;
struct stat stat_buf;
- if (!ivars->fullpath) {
- ivars->fullpath = CB_new(CB_Get_Size(ivars->dir) + 20);
- }
- CB_setf(ivars->fullpath, "%o%s%o", ivars->dir, CHY_DIR_SEP,
- ivars->entry);
- if (stat((char*)CB_Get_Ptr8(ivars->fullpath), &stat_buf) != -1) {
- if (stat_buf.st_mode & S_IFLNK) { return true; }
+ CharBuf *fullpath = CB_newf("%o%s%o", ivars->dir, CHY_DIR_SEP,
+ ivars->entry);
+ if (stat((char*)CB_Get_Ptr8(fullpath), &stat_buf) != -1) {
+ if (stat_buf.st_mode & S_IFLNK) { retval = true; }
}
- return false;
+ DECREF(fullpath);
+ return retval;
}
#endif // CHY_HAS_DIRENT_D_TYPE
}
@@ -308,10 +305,6 @@ FSDH_Entry_Is_Symlink_IMP(FSDirHandle *self) {
bool
FSDH_Close_IMP(FSDirHandle *self) {
FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
- if (ivars->fullpath) {
- CB_Dec_RefCount(ivars->fullpath);
- ivars->fullpath = NULL;
- }
if (ivars->sys_dirhandle) {
DIR *sys_dirhandle = (DIR*)ivars->sys_dirhandle;
ivars->sys_dirhandle = NULL;
http://git-wip-us.apache.org/repos/asf/lucy/blob/5169be5e/core/Lucy/Store/FSDirHandle.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FSDirHandle.cfh b/core/Lucy/Store/FSDirHandle.cfh
index 88700ea..0d39341 100644
--- a/core/Lucy/Store/FSDirHandle.cfh
+++ b/core/Lucy/Store/FSDirHandle.cfh
@@ -23,7 +23,6 @@ class Lucy::Store::FSDirHandle cnick FSDH
void *sys_dirhandle;
void *sys_dir_entry;
- CharBuf *fullpath;
Err *saved_error;
bool delayed_iter;