]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
lib/base64: optimize base64_decode() with reverse lookup tables
authorKuan-Wei Chiu <visitorckw@gmail.com>
Fri, 14 Nov 2025 06:01:07 +0000 (14:01 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 20 Nov 2025 22:03:44 +0000 (14:03 -0800)
commitc4eb7ad32eab13ba64cc452c6f43d518b63f5e03
tree3f7b0ab394c72fc7e425156f48e63d3fc1b6fcb9
parentf1e2ca801c54dfc09d6a5540207cec25e8d43f6f
lib/base64: optimize base64_decode() with reverse lookup tables

Replace the use of strchr() in base64_decode() with precomputed reverse
lookup tables for each variant. This avoids repeated string scans and
improves performance. Use -1 in the tables to mark invalid characters.

Decode:
  64B   ~1530ns  ->  ~80ns    (~19.1x)
  1KB  ~27726ns  -> ~1239ns   (~22.4x)

[akpm@linux-foundation.org: fix kernedoc]
Link: https://lkml.kernel.org/r/20251114060107.89026-1-409411716@gms.tku.edu.tw
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Co-developed-by: Guan-Chun Wu <409411716@gms.tku.edu.tw>
Signed-off-by: Guan-Chun Wu <409411716@gms.tku.edu.tw>
Reviewed-by: David Laight <david.laight.linux@gmail.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Eric Biggers <ebiggers@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Keith Busch <kbusch@kernel.org>
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: "Theodore Y. Ts'o" <tytso@mit.edu>
Cc: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Cc: Xiubo Li <xiubli@redhat.com>
Cc: Yu-Sheng Huang <home7438072@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/base64.c