From patchwork Tue Dec 18 14:36:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Heimpold X-Patchwork-Id: 10735773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C08211399 for ; Tue, 18 Dec 2018 14:36:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B044B29823 for ; Tue, 18 Dec 2018 14:36:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4C2A29C08; Tue, 18 Dec 2018 14:36:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DC6029823 for ; Tue, 18 Dec 2018 14:36:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726648AbeLROg1 (ORCPT ); Tue, 18 Dec 2018 09:36:27 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:40997 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726712AbeLROg1 (ORCPT ); Tue, 18 Dec 2018 09:36:27 -0500 Received: from localhost.localdomain ([109.104.51.109]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MmkfQ-1hJ5532SYA-00jtJD; Tue, 18 Dec 2018 15:36:19 +0100 From: Michael Heimpold To: linux-mmc@vger.kernel.org, chris@printf.net Cc: Michael Heimpold , Michael Heimpold Subject: [PATCH mmc-utils 4/5] Optimize to_binstr() function Date: Tue, 18 Dec 2018 15:36:00 +0100 Message-Id: <20181218143601.24413-5-michael.heimpold@i2se.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181218143601.24413-1-michael.heimpold@i2se.com> References: <20181218143601.24413-1-michael.heimpold@i2se.com> X-Provags-ID: V03:K1:KPmfjvm9dbAMLa6o+OqvRVUNYJVVEakFYC3KBCNrA/WbWN3VbGq y4Z8fwHXU9C/Di1v0RklvtkNrp4/tO4aOcnW8iq4EO27u1TuKFSaECxtR9Eu/M0SSnA6FRf GSDb7zf2j1CxVgh1hkcqLl2a1j0uIGXOQHgFuBWGqUE8M9yuiZberrO+K9n4xEH7dYHTt5L WPbRaMGfER2JA17nlP7pg== X-UI-Out-Filterresults: notjunk:1;V03:K0:WMeFkvldl3o=:uEtet0ZmEMuQDwsafxpA9A h+NzmfDSykjUp7dBFX9murbDp0XnHrAm49YN2FJ/vHCbm3wNsPps49TafUzI4yUxl4b98pzDR +xe9OJKnPZL5/CgqSKsKIGpBR9iOY/WA1zxOALSW59xkxVJ2sy9rl1WaPZjBMfyRjvTRTtAHl DJy7UCo3dLoMWkzLMhXmnFfNjUYlFOt6BCHxpUqSlNivNISCqXSjIigTekW+fmMJiPw1V4U14 Y+hU2ujPDIhnz3BtA3DfRmkCoYT8E2V/6/heZcqVb49Ga9tFWyKegz+/ye39XgVq3ufWbnH9Q oN9LOblufsc70hrdOaSlgnyPf4qrmZwj1a4f3NbBbQRXd1OvKT3DUHNKXH4Y62QT0gBWZAQVW kT2zE88YHNZCu4YglWrqKIGORQeCvCu+3/djxPLCkUoTOcJv8icvhpWqgwZH5azOGvbbCeNyQ R28k2+wc+ubiqP4luXZV0rYsIYkG6GswglRlKeS5kVc2nWEWMHr8IVW5h8OqeEAiZmbgzeIKJ 1Y7UqV2EJcJl/58rjq12qSH5wiuLWlT5gAXZL01UsCEUsZ1XqRlsZFxJwOlBASgcj3sKzotOa BxgPSgOffyu2D8BQURxjqvaBzFq46XX2fX6evef72RwJ7pvXQUPggsv1hR5tPYtAZk35agsC0 /TgT24Eh9xvUqvw58XIo0EJWBltsmP6vnZ7QSC63kGwQi9PXy2PhBE4GODAYcbvsCdm2CVCqN HvyNnAoW65cuUOuGXUEcW9kyqSwUISZ4vyQMvE46MGlNbYHWuonYYZpA0Ic= Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Appending multiple times to same string is slow since strcat() needs to determine the end during each run. So manually maintain a pointer to the end to speed-up things. Signed-off-by: Michael Heimpold Cc: Michael Heimpold --- lsmmc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lsmmc.c b/lsmmc.c index e64117c..86713f7 100644 --- a/lsmmc.c +++ b/lsmmc.c @@ -371,12 +371,14 @@ char *to_binstr(char *hexstr) "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111", }; - char *binstr; + char *binstr, *tail; binstr = calloc(strlen(hexstr) * 4 + 1, sizeof(char)); if (!binstr) return NULL; + tail = binstr; + while (hexstr && *hexstr != '\0') { if (!isxdigit(*hexstr)) { free(binstr); @@ -384,13 +386,14 @@ char *to_binstr(char *hexstr) } if (isdigit(*hexstr)) - strcat(binstr, bindigits[*hexstr - '0']); + strcat(tail, bindigits[*hexstr - '0']); else if (islower(*hexstr)) - strcat(binstr, bindigits[*hexstr - 'a' + 10]); + strcat(tail, bindigits[*hexstr - 'a' + 10]); else - strcat(binstr, bindigits[*hexstr - 'A' + 10]); + strcat(tail, bindigits[*hexstr - 'A' + 10]); hexstr++; + tail += 4; } return binstr;