aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ic
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2018-04-19 16:23:05 +0200
committerErlang/OTP <[email protected]>2018-04-19 16:23:05 +0200
commit7920c389594797153cc27ac6dea206fbd44de331 (patch)
tree3faee5613d82bbaf39fcd179df724e05df6ac399 /lib/ic
parent16839ce761919b809c0154cd5f5262f940052a15 (diff)
parent1ab478a7ce281f7cdce01df2fe04953c0770fdbc (diff)
downloadotp-7920c389594797153cc27ac6dea206fbd44de331.tar.gz
otp-7920c389594797153cc27ac6dea206fbd44de331.tar.bz2
otp-7920c389594797153cc27ac6dea206fbd44de331.zip
Merge branch 'sverker/optimize-atom-enc-dec/ERIERL-150/OTP-15023' into maint-20
* sverker/optimize-atom-enc-dec/ERIERL-150/OTP-15023: erl_interface: Optimize latin1_to_utf8 and friend ic: Optimize oe_ei_encode_atom
Diffstat (limited to 'lib/ic')
-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);
}