Skip to content

Commit e118f4c

Browse files
committed
ChatON:ChatTmplApply: Avoid the stringstream
1 parent c7d58a0 commit e118f4c

File tree

1 file changed

+1
-19
lines changed

1 file changed

+1
-19
lines changed

common/chaton.hpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,7 @@ inline bool chaton_tmpl_apply_ex(
428428
return false;
429429
}
430430
ChatParts cp = {};
431-
std::stringstream ss;
432431
std::string globalBegin = chaton_tmpl_role_kv(tmpl, K_GLOBAL, {K_BEGIN});
433-
ss << globalBegin;
434432
cp.add_part(ChatParts::S, globalBegin);
435433
int cntSystem = 0;
436434
int cntUser = 0;
@@ -444,63 +442,47 @@ inline bool chaton_tmpl_apply_ex(
444442
auto end = chaton_tmpl_role_kv(tmpl, role, {K_END});
445443
if (role == K_SYSTEM) {
446444
cntSystem += 1;
447-
ss << begin << prefix;
448445
cp.add_part(ChatParts::S, begin);
449446
cp.add_part(ChatParts::S, prefix);
450447
} else if (role == K_USER) {
451448
cntUser += 1;
452449
if ((cntSystem == 1) && (cntUser == 1)) {
453450
if (conMeta[tmpl][K_SYSTEMUSER_1ST_USER_HAS_BEGIN]) {
454-
ss << begin;
455451
cp.add_part(ChatParts::S, begin);
456452
}
457453
if (conMeta[tmpl][K_SYSTEMUSER_1ST_USER_HAS_PREFIX]) {
458-
ss << prefix;
459454
cp.add_part(ChatParts::S, prefix);
460455
}
461456
} else {
462-
ss << begin << prefix;
463457
cp.add_part(ChatParts::S, begin);
464458
cp.add_part(ChatParts::S, prefix);
465459
}
466460
} else {
467461
cntOthers += 1;
468-
ss << begin << prefix;
469462
cp.add_part(ChatParts::S, begin);
470463
cp.add_part(ChatParts::S, prefix);
471464
}
472-
ss << content;
473465
cp.add_part(ChatParts::N, content);
474466
if (role == K_SYSTEM) {
475467
if (chaton_tmpl_kv_bool(tmpl, K_SYSTEMUSER_SYSTEM_HAS_SUFFIX)) {
476-
ss << suffix;
477468
cp.add_part(ChatParts::S, suffix);
478469
}
479470
if (chaton_tmpl_kv_bool(tmpl, K_SYSTEMUSER_SYSTEM_HAS_END)) {
480-
ss << end;
481471
cp.add_part(ChatParts::S, end);
482472
}
483473
} else {
484-
ss << suffix << end;
485474
cp.add_part(ChatParts::S, suffix);
486475
cp.add_part(ChatParts::S, end);
487476
}
488477
}
489478
if (alertAssistantAtEnd) {
490479
auto assistantBeginPrefix = chaton_tmpl_role_kv(tmpl, K_ASSISTANT, {K_BEGIN, K_PREFIX});
491-
ss << assistantBeginPrefix;
492480
cp.add_part(ChatParts::S, assistantBeginPrefix);
493481
}
494482
auto globalEnd = chaton_tmpl_role_kv(tmpl, K_GLOBAL, {K_END});
495-
ss << globalEnd;
496483
cp.add_part(ChatParts::S, globalEnd);
497484
cp.dump();
498-
tagged = ss.str();
499-
std::string cpStr = cp.str();
500-
if (tagged != cpStr) {
501-
LOG_TEELN("DBUG:%s:Mismatch between CP[%s] and SS[%s]", __func__, cpStr.c_str(), tagged.c_str());
502-
exit(2);
503-
}
485+
tagged = cp.str();
504486
LOGLN("DBUG:%s:%s:%s", __func__, tmpl.c_str(), tagged.c_str());
505487
LOGLN("DBUG:%s:%s:CntSys[%d]:CntUsr[%d]:CntOthers[%d]", __func__, tmpl.c_str(), cntSystem, cntUser, cntOthers);
506488
types = cp.get_types();

0 commit comments

Comments
 (0)