From: "J. R. Okajima" <hooanon05g@gmail.com>
To: james.smart@broadcom.com
Cc: sagi@grimberg.me, james_p_freyensee@linux.intel.com,
linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org,
linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4] add u64 number parser
Date: Tue, 31 Jan 2017 00:08:00 +0900 [thread overview]
Message-ID: <26045.1485788880@jrobl> (raw)
Hello James,
Your commit
a317178 2016-12-06 parser: add u64 number parser
was merged into v4.10-rc1. Good.
I have a very similar function and used for a long time. Here I'd
suggest you a tiny optimization based on my version.
If you think another value is more apropriate as the size of an internal
array, you can change it freely.
J. R. Okajima
commit 030361e78d327d9d89254dc3b320c092221c7cd0
Author: J. R. Okajima <hooanon05g@gmail.com>
Date: Tue Jan 31 00:01:16 2017 +0900
parser: match_u64, short string optimization
=
When the given string is short enough, we can skip kmalloc/kfree.
Signed-off-by: J. R. Okajima <hooanon05g@gmail.com>
diff --git a/lib/parser.c b/lib/parser.c
index 3278958..cfbc6ec 100644
--- a/lib/parser.c
+++ b/lib/parser.c
@@ -163,21 +163,25 @@ static int match_number(substring_t *s, int *result,=
int base)
*/
static int match_u64int(substring_t *s, u64 *result, int base)
{
- char *buf;
+ char *buf, a[32];
int ret;
u64 val;
size_t len =3D s->to - s->from;
=
- buf =3D kmalloc(len + 1, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
+ buf =3D a;
+ if (len + 1 > sizeof(a)) {
+ buf =3D kmalloc(len + 1, GFP_KERNEL);
+ if (unlikely(!buf))
+ return -ENOMEM;
+ }
memcpy(buf, s->from, len);
buf[len] =3D '\0';
=
ret =3D kstrtoull(buf, base, &val);
if (!ret)
*result =3D val;
- kfree(buf);
+ if (buf !=3D a)
+ kfree(buf);
return ret;
}
=
next reply other threads:[~2017-01-30 15:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-30 15:08 J. R. Okajima [this message]
-- strict thread matches above, loose matches on Subject: below --
2016-09-25 16:14 [PATCH v4] add u64 number parser James Smart
2016-09-27 0:42 ` J Freyensee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=26045.1485788880@jrobl \
--to=hooanon05g@gmail.com \
--cc=james.smart@broadcom.com \
--cc=james_p_freyensee@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox