Minor optimization to msg size counter

This commit is contained in:
2015-06-13 18:05:32 +02:00
parent c5a4b93aee
commit 08ecfe9e1a
+15 -6
View File
@@ -607,9 +607,10 @@ function splitMsg(msg) {
msgs = [],
encoding = defs.encodings.detect(msg),
totBitCount = bitCount(msg, encoding),
partBitCount,
udh,
i;
i,
i2,
partCharLimit;
// A single message could contain up to 1120 bits
// Return directly if the message fits into that
@@ -626,16 +627,24 @@ function splitMsg(msg) {
log.silly('larvitsmpp: lib/utils.js: splitMsg() - bundleMsgId set to ' + bundleMsgId);
i = 0;
if (encoding === 'ASCII') {
partCharLimit = 153;
} else {
partCharLimit = 67;
}
i = 0;
i2 = 0;
while (msg[i] !== undefined) {
msgPart += msg[i];
partBitCount = bitCount(msgPart, encoding);
i2 ++;
if (partBitCount > 1072) {
if (i2 === partCharLimit) {
// We've reached the message limit
log.debug('larvitsmpp: lib/utils.js: splitMsg() - Msg part defined. partBitCount: ' + partBitCount + ' msgPart: "' + msgPart + '"');
// Reset the local counter
i2 = 0;
// Add this msgPart minus the last character to the msgs array as an encoded buffer
msgs.push(defs.encodings[encoding].encode(msgPart.slice(0, - 1)));