aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ic/c_src
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2018-03-19 16:03:03 +0100
committerSverker Eriksson <[email protected]>2018-03-19 16:03:03 +0100
commit1d3acb70debd134c8346b7e98347171d5cf6fc62 (patch)
treea8c9bafe833f12768a1aeb625f33873e6f26dbf1 /lib/ic/c_src
parent194513197e19cd592f3f5c2231510542f5193fe4 (diff)
downloadotp-1d3acb70debd134c8346b7e98347171d5cf6fc62.tar.gz
otp-1d3acb70debd134c8346b7e98347171d5cf6fc62.tar.bz2
otp-1d3acb70debd134c8346b7e98347171d5cf6fc62.zip
ic: Optimize oe_ei_encode_atom
1. Use ei_encode_atom_len to not repeat strlen(p) twice. 2. Do a dirty over estimation of atom encoding space needed to avoid calling ei_encode_atom_len twice.
Diffstat (limited to 'lib/ic/c_src')
-rw-r--r--lib/ic/c_src/oe_ei_encode_atom.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/lib/ic/c_src/oe_ei_encode_atom.c b/lib/ic/c_src/oe_ei_encode_atom.c
index 758586d1d4..99a9fe26f0 100644
--- a/lib/ic/c_src/oe_ei_encode_atom.c
+++ b/lib/ic/c_src/oe_ei_encode_atom.c
@@ -20,28 +20,37 @@
*/
#include <ic.h>
+#include <string.h>
+
+
+#define DIRTY_ATOM_ENC_MAX(LATIN1_CHARS) ((LATIN1_CHARS)*2 + 3)
+
int oe_ei_encode_atom(CORBA_Environment *ev, const char *p) {
int size = ev->_iout;
+ size_t len = strlen(p);
+
+ if (DIRTY_ATOM_ENC_MAX(len) >= ev->_outbufsz) {
+
+ ei_encode_atom_len(0,&size,p,len);
+
+ if (size >= ev->_outbufsz) {
+ char *buf = ev->_outbuf;
+ int bufsz = ev->_outbufsz + ev->_memchunk;
+
+ while (size >= bufsz)
+ bufsz += ev->_memchunk;
+
+ if ((buf = realloc(buf, bufsz)) == NULL) {
+ CORBA_exc_set(ev, CORBA_SYSTEM_EXCEPTION, NO_MEMORY, "End of heap memory while encoding");
+ return -1; /* OUT OF MEMORY */
+ }
- ei_encode_atom(0,&size,p);
-
- if (size >= ev->_outbufsz) {
- char *buf = ev->_outbuf;
- int bufsz = ev->_outbufsz + ev->_memchunk;
-
- while (size >= bufsz)
- bufsz += ev->_memchunk;
-
- if ((buf = realloc(buf, bufsz)) == NULL) {
- CORBA_exc_set(ev, CORBA_SYSTEM_EXCEPTION, NO_MEMORY, "End of heap memory while encoding");
- return -1; /* OUT OF MEMORY */
- }
-
- ev->_outbuf = buf;
- ev->_outbufsz = bufsz;
+ ev->_outbuf = buf;
+ ev->_outbufsz = bufsz;
+ }
}
- return ei_encode_atom(ev->_outbuf,&ev->_iout,p);
+ return ei_encode_atom_len(ev->_outbuf,&ev->_iout,p,len);
}