Minor optimization to msg size counter
This commit is contained in:
+15
-6
@@ -607,9 +607,10 @@ function splitMsg(msg) {
|
|||||||
msgs = [],
|
msgs = [],
|
||||||
encoding = defs.encodings.detect(msg),
|
encoding = defs.encodings.detect(msg),
|
||||||
totBitCount = bitCount(msg, encoding),
|
totBitCount = bitCount(msg, encoding),
|
||||||
partBitCount,
|
|
||||||
udh,
|
udh,
|
||||||
i;
|
i,
|
||||||
|
i2,
|
||||||
|
partCharLimit;
|
||||||
|
|
||||||
// A single message could contain up to 1120 bits
|
// A single message could contain up to 1120 bits
|
||||||
// Return directly if the message fits into that
|
// 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);
|
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) {
|
while (msg[i] !== undefined) {
|
||||||
msgPart += msg[i];
|
msgPart += msg[i];
|
||||||
|
|
||||||
partBitCount = bitCount(msgPart, encoding);
|
i2 ++;
|
||||||
|
|
||||||
if (partBitCount > 1072) {
|
if (i2 === partCharLimit) {
|
||||||
// We've reached the message limit
|
// 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
|
// 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)));
|
msgs.push(defs.encodings[encoding].encode(msgPart.slice(0, - 1)));
|
||||||
|
|||||||
Reference in New Issue
Block a user