From 2007cfd3a04a9ef2c3ae55bc1690d810ae362d21 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 4 Jul 2019 15:43:50 +0100 Subject: [PATCH] Improved efficiency of Dish title generation --- src/core/Dish.mjs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/core/Dish.mjs b/src/core/Dish.mjs index f8d7dfd8..dd3c8c2f 100755 --- a/src/core/Dish.mjs +++ b/src/core/Dish.mjs @@ -166,29 +166,27 @@ class Dish { */ async getTitle(maxLength) { let title = ""; - const cloned = this.clone(); + let cloned; switch (this.type) { case Dish.FILE: - title = cloned.value.name; + title = this.value.name; break; case Dish.LIST_FILE: - title = `${cloned.value.length} file(s)`; + title = `${this.value.length} file(s)`; break; case Dish.ARRAY_BUFFER: case Dish.BYTE_ARRAY: - title = await cloned.detectDishType(); - if (title === null) { - cloned.value = cloned.value.slice(0, 2048); - title = await cloned.get(Dish.STRING); - } - break; + title = await this.detectDishType(); + if (title !== null) break; + // fall through if no mime type was detected default: + cloned = this.clone(); + cloned.value = cloned.value.slice(0, 256); title = await cloned.get(Dish.STRING); } - title = title.slice(0, maxLength); - return title; + return title.slice(0, maxLength); }