summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-11-25 00:07:54 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-11-25 00:09:40 -0300
commitbc2e8d99e5ae0dbd69e712cc71da3033f5f30139 (patch)
treed836011e3d5873e3ceea328ea3100f3c7719ab99 /core/io
parent7dfba3cda9f13427f9f10a6eefbec52aef62274c (diff)
Made Vector::ptrw explicit for writing, compiler was sometimes using the wrong function,
leading to unnecesary copy on writes and reduced performance.
Diffstat (limited to 'core/io')
-rw-r--r--core/io/file_access_compressed.cpp24
-rw-r--r--core/io/file_access_encrypted.cpp12
-rw-r--r--core/io/file_access_network.cpp6
-rw-r--r--core/io/stream_peer.cpp6
4 files changed, 24 insertions, 24 deletions
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index 514e3c65f0..c6f31dc8f0 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -51,7 +51,7 @@ void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_
if (write_max > write_buffer_size) { \
write_buffer_size = next_power_of_2(write_max); \
buffer.resize(write_buffer_size); \
- write_ptr = buffer.ptr(); \
+ write_ptr = buffer.ptrw(); \
} \
}
@@ -76,14 +76,14 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
comp_buffer.resize(max_bs);
buffer.resize(block_size);
- read_ptr = buffer.ptr();
- f->get_buffer(comp_buffer.ptr(), read_blocks[0].csize);
+ read_ptr = buffer.ptrw();
+ f->get_buffer(comp_buffer.ptrw(), read_blocks[0].csize);
at_end = false;
read_eof = false;
read_block_count = bc;
read_block_size = read_blocks.size() == 1 ? read_total : block_size;
- Compression::decompress(buffer.ptr(), read_block_size, comp_buffer.ptr(), read_blocks[0].csize, cmode);
+ Compression::decompress(buffer.ptrw(), read_block_size, comp_buffer.ptr(), read_blocks[0].csize, cmode);
read_block = 0;
read_pos = 0;
@@ -114,7 +114,7 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
write_buffer_size = 256;
buffer.resize(256);
write_max = 0;
- write_ptr = buffer.ptr();
+ write_ptr = buffer.ptrw();
//don't store anything else unless it's done saving!
} else {
@@ -160,7 +160,7 @@ void FileAccessCompressed::close() {
Vector<uint8_t> cblock;
cblock.resize(Compression::get_max_compressed_buffer_size(bl, cmode));
- int s = Compression::compress(cblock.ptr(), bp, bl, cmode);
+ int s = Compression::compress(cblock.ptrw(), bp, bl, cmode);
f->store_buffer(cblock.ptr(), s);
block_sizes.push_back(s);
@@ -211,8 +211,8 @@ void FileAccessCompressed::seek(size_t p_position) {
read_block = block_idx;
f->seek(read_blocks[read_block].offset);
- f->get_buffer(comp_buffer.ptr(), read_blocks[read_block].csize);
- Compression::decompress(buffer.ptr(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
+ f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
+ Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
read_block_size = read_block == read_block_count - 1 ? read_total % block_size : block_size;
}
@@ -282,8 +282,8 @@ uint8_t FileAccessCompressed::get_8() const {
if (read_block < read_block_count) {
//read another block of compressed data
- f->get_buffer(comp_buffer.ptr(), read_blocks[read_block].csize);
- Compression::decompress(buffer.ptr(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
+ f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
+ Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
read_block_size = read_block == read_block_count - 1 ? read_total % block_size : block_size;
read_pos = 0;
@@ -315,8 +315,8 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
if (read_block < read_block_count) {
//read another block of compressed data
- f->get_buffer(comp_buffer.ptr(), read_blocks[read_block].csize);
- Compression::decompress(buffer.ptr(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
+ f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
+ Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
read_block_size = read_block == read_block_count - 1 ? read_total % block_size : block_size;
read_pos = 0;
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index e5da307153..71ebf57508 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -80,11 +80,11 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
data.resize(ds);
- uint32_t blen = p_base->get_buffer(data.ptr(), ds);
+ uint32_t blen = p_base->get_buffer(data.ptrw(), ds);
ERR_FAIL_COND_V(blen != ds, ERR_FILE_CORRUPT);
aes256_context ctx;
- aes256_init(&ctx, key.ptr());
+ aes256_init(&ctx, key.ptrw());
for (size_t i = 0; i < ds; i += 16) {
@@ -97,7 +97,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
MD5_CTX md5;
MD5Init(&md5);
- MD5Update(&md5, data.ptr(), data.size());
+ MD5Update(&md5, (uint8_t *)data.ptr(), data.size());
MD5Final(&md5);
ERR_FAIL_COND_V(String::md5(md5.digest) != String::md5(md5d), ERR_FILE_CORRUPT);
@@ -141,17 +141,17 @@ void FileAccessEncrypted::close() {
MD5_CTX md5;
MD5Init(&md5);
- MD5Update(&md5, data.ptr(), data.size());
+ MD5Update(&md5, (uint8_t *)data.ptr(), data.size());
MD5Final(&md5);
compressed.resize(len);
- zeromem(compressed.ptr(), len);
+ zeromem(compressed.ptrw(), len);
for (int i = 0; i < data.size(); i++) {
compressed[i] = data[i];
}
aes256_context ctx;
- aes256_init(&ctx, key.ptr());
+ aes256_init(&ctx, key.ptrw());
for (size_t i = 0; i < len; i += 16) {
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index a224abd9e7..61a0521cae 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -147,7 +147,7 @@ void FileAccessNetworkClient::_thread_func() {
Vector<uint8_t> block;
block.resize(len);
- client->get_data(block.ptr(), len);
+ client->get_data(block.ptrw(), len);
if (fa) //may have been queued
fa->_set_block(offset, block);
@@ -434,12 +434,12 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
_queue_page(page + j);
}
- buff = pages[page].buffer.ptr();
+ buff = pages[page].buffer.ptrw();
//queue pages
buffer_mutex->unlock();
}
- buff = pages[page].buffer.ptr();
+ buff = pages[page].buffer.ptrw();
last_page_buff = buff;
last_page = page;
}
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index 2583eb369d..42a258a10d 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -220,7 +220,7 @@ void StreamPeer::put_var(const Variant &p_variant) {
encode_variant(p_variant, NULL, len);
buf.resize(len);
put_32(len);
- encode_variant(p_variant, buf.ptr(), len);
+ encode_variant(p_variant, buf.ptrw(), len);
put_data(buf.ptr(), buf.size());
}
@@ -340,7 +340,7 @@ String StreamPeer::get_utf8_string(int p_bytes) {
Vector<uint8_t> buf;
Error err = buf.resize(p_bytes);
ERR_FAIL_COND_V(err != OK, String());
- err = get_data(buf.ptr(), p_bytes);
+ err = get_data(buf.ptrw(), p_bytes);
ERR_FAIL_COND_V(err != OK, String());
String ret;
@@ -353,7 +353,7 @@ Variant StreamPeer::get_var() {
Vector<uint8_t> var;
Error err = var.resize(len);
ERR_FAIL_COND_V(err != OK, Variant());
- err = get_data(var.ptr(), len);
+ err = get_data(var.ptrw(), len);
ERR_FAIL_COND_V(err != OK, Variant());
Variant ret;