Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve write time by using a byte lookup table #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/πfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ static int pifs_read(const char *path, char *buf, size_t count, off_t offset,
return count;
}

static unsigned short bytesIndices[256] = {0};
static int pifs_write(const char *path, const char *buf, size_t count,
off_t offset, struct fuse_file_info *info)
{
Expand All @@ -185,13 +186,7 @@ static int pifs_write(const char *path, const char *buf, size_t count,
}

for (size_t i = 0; i < count; i++) {
short index;
for (index = 0; index < SHRT_MAX; index++) {
if (get_byte(index) == *buf) {
break;
}
}
ret = write(info->fh, &index, sizeof index);
ret = write(info->fh, &bytesIndices[(unsigned char)*buf], sizeof(unsigned short));
if (ret == -1) {
return -errno;
}
Expand Down Expand Up @@ -271,7 +266,7 @@ static int pifs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
do {
errno = 0;
struct dirent *de = readdir(dir);
if (!de) {
if (!de) {
if (errno) {
return -errno;
} else {
Expand Down Expand Up @@ -390,6 +385,18 @@ static struct fuse_operations pifs_ops = {

int main (int argc, char *argv[])
{
int found = 0;
for(unsigned short i = 1; i < USHRT_MAX; i++)
{
unsigned char val = get_byte(i);
if(bytesIndices[val] == 0)
{
bytesIndices[val] = i;
if(++found == 256)
break;
}
}

int ret;
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);

Expand Down