Skip to content

Commit 899b48a

Browse files
committed
refactor: Remove unnecessary conditionals for empty token vectors
Branch: GraniteDocling Signed-off-by: Gabe Goodhart <[email protected]>
1 parent 64fc676 commit 899b48a

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

tools/mtmd/mtmd.cpp

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -525,21 +525,15 @@ struct mtmd_tokenizer {
525525

526526
// add overview image (first)
527527
if (ctx->ov_img_first) {
528-
if (!ctx->tok_ov_img_start.empty()) {
529-
add_text(ctx->tok_ov_img_start);
530-
}
528+
add_text(ctx->tok_ov_img_start);
531529
cur.entries.emplace_back(std::move(ov_chunk));
532-
if (!ctx->tok_ov_img_end.empty()) {
533-
add_text(ctx->tok_ov_img_end);
534-
}
530+
add_text(ctx->tok_ov_img_end);
535531
}
536532

537533
// add slices (or tiles)
538534
if (!chunks.empty()) {
539535
GGML_ASSERT((int)chunks.size() == n_row * n_col);
540-
if (!ctx->tok_slices_start.empty()) {
541-
add_text(ctx->tok_slices_start);
542-
}
536+
add_text(ctx->tok_slices_start);
543537
for (int y = 0; y < n_row; y++) {
544538
for (int x = 0; x < n_col; x++) {
545539
const bool is_last_in_row = (x == n_col - 1);
@@ -553,31 +547,23 @@ struct mtmd_tokenizer {
553547
add_text(std::string(buf.get(), buf.get() + sz - 1), true);
554548
}
555549
cur.entries.emplace_back(std::move(chunks[y * n_col + x]));
556-
if (!ctx->tok_sli_img_end.empty()) {
557-
add_text(ctx->tok_sli_img_end);
558-
}
559-
if (!is_last_in_row && !ctx->tok_sli_img_mid.empty()) {
550+
add_text(ctx->tok_sli_img_end);
551+
if (!is_last_in_row) {
560552
add_text(ctx->tok_sli_img_mid);
561553
}
562554
}
563-
if ((y != n_row - 1 || ctx->tok_row_end_trail) && !ctx->tok_row_end.empty()) {
555+
if ((y != n_row - 1 || ctx->tok_row_end_trail)) {
564556
add_text(ctx->tok_row_end);
565557
}
566558
}
567-
if (!ctx->tok_slices_end.empty()) {
568-
add_text(ctx->tok_slices_end);
569-
}
559+
add_text(ctx->tok_slices_end);
570560
}
571561

572562
// add overview image (last)
573563
if (!ctx->ov_img_first) {
574-
if (!ctx->tok_ov_img_start.empty()) {
575-
add_text(ctx->tok_ov_img_start);
576-
}
564+
add_text(ctx->tok_ov_img_start);
577565
cur.entries.emplace_back(std::move(ov_chunk));
578-
if (!ctx->tok_ov_img_end.empty()) {
579-
add_text(ctx->tok_ov_img_end);
580-
}
566+
add_text(ctx->tok_ov_img_end);
581567
}
582568

583569
} else {

0 commit comments

Comments
 (0)