mirror of
https://github.com/wiiu-env/wut.git
synced 2024-12-05 03:24:17 +01:00
wutdevoptab: Only allocate a new buffer if the given buffer is not aligned properly (#159)
This commit is contained in:
parent
81d689ed76
commit
79b8597a68
@ -27,10 +27,24 @@ __wut_fs_read(struct _reent *r,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((((uintptr_t) ptr) & 0x3F) == 0){
|
||||
status = FSReadFile(__wut_devoptab_fs_client, &cmd, (uint8_t *) ptr, 1,
|
||||
len, file->fd, 0, -1);
|
||||
if(status > 0){
|
||||
bytesRead = (uint32_t) status;
|
||||
file->offset += bytesRead;
|
||||
}
|
||||
} else {
|
||||
// Copy to internal buffer due to alignment requirement and read in chunks.
|
||||
alignedReadBuffer = memalign(0x40, 8192);
|
||||
// Using a buffer smaller than 128KiB takes a performance hit.
|
||||
int buffer_size = len < 128*1024 ? len : 128*1024;
|
||||
alignedReadBuffer = memalign(0x40, buffer_size);
|
||||
if(!alignedReadBuffer){
|
||||
r->_errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
while (len > 0) {
|
||||
size_t toRead = len > 8192 ? 8192 : len;
|
||||
size_t toRead = len > buffer_size ? buffer_size : len;
|
||||
|
||||
// Write the data
|
||||
status = FSReadFile(__wut_devoptab_fs_client, &cmd, alignedReadBuffer, 1,
|
||||
@ -55,6 +69,7 @@ __wut_fs_read(struct _reent *r,
|
||||
}
|
||||
}
|
||||
free(alignedReadBuffer);
|
||||
}
|
||||
|
||||
// Return partial read
|
||||
if (bytesRead > 0) {
|
||||
|
@ -27,10 +27,24 @@ __wut_fs_write(struct _reent *r,
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Copy to internal buffer due to alignment requirement and write in chunks.
|
||||
alignedWriteBuffer = memalign(0x40, 8192);
|
||||
if((((uintptr_t) ptr) & 0x3F) == 0){
|
||||
status = FSWriteFile(__wut_devoptab_fs_client, &cmd, (uint8_t *) ptr,
|
||||
1, len, file->fd, 0, -1);
|
||||
if(status > 0){
|
||||
bytesWritten = (uint32_t) status;
|
||||
file->offset += bytesWritten;
|
||||
}
|
||||
} else {
|
||||
// Copy to internal buffer due to alignment requirement and read in chunks.
|
||||
// Using a buffer smaller than 128KiB takes a performance hit.
|
||||
int buffer_size = len < 128*1024 ? len : 128*1024;
|
||||
alignedWriteBuffer = memalign(0x40, buffer_size);
|
||||
if(!alignedWriteBuffer){
|
||||
r->_errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
while (len > 0) {
|
||||
size_t toWrite = len > 8192 ? 8192 : len;
|
||||
size_t toWrite = len > buffer_size ? buffer_size : len;
|
||||
|
||||
// Copy to internal buffer
|
||||
memcpy(alignedWriteBuffer, ptr, toWrite);
|
||||
@ -53,6 +67,7 @@ __wut_fs_write(struct _reent *r,
|
||||
}
|
||||
}
|
||||
free(alignedWriteBuffer);
|
||||
}
|
||||
|
||||
// Return partial write
|
||||
if (bytesWritten > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user