From f393d48cdcd3f517c7e448e371ca3bf64a65cd47 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sat, 2 Mar 2024 09:29:22 -0500 Subject: [PATCH] Inline CBS_init, CBS_data, and CBS_len These are very basic accessors and we'll never make CBS opaque. Just inline them so the compiler can optimize around them. Change-Id: I65442acb9a89a611082c7e0c82b365c78adae7f4 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/66727 Auto-Submit: David Benjamin Reviewed-by: Bob Beck Commit-Queue: David Benjamin (cherry picked from commit e202e51cb0912f36dafbd2e67cf04d6ec82f3180) --- crypto/bytestring/cbs.c | 9 --------- include/openssl/bytestring.h | 9 ++++++--- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/crypto/bytestring/cbs.c b/crypto/bytestring/cbs.c index 5bb5f2e7935..1dba1c8e49c 100644 --- a/crypto/bytestring/cbs.c +++ b/crypto/bytestring/cbs.c @@ -31,11 +31,6 @@ #include "internal.h" -void CBS_init(CBS *cbs, const uint8_t *data, size_t len) { - cbs->data = data; - cbs->len = len; -} - static int cbs_get(CBS *cbs, const uint8_t **p, size_t n) { if (cbs->len < n) { return 0; @@ -52,10 +47,6 @@ int CBS_skip(CBS *cbs, size_t len) { return cbs_get(cbs, &dummy, len); } -const uint8_t *CBS_data(const CBS *cbs) { return cbs->data; } - -size_t CBS_len(const CBS *cbs) { return cbs->len; } - int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len) { OPENSSL_free(*out_ptr); *out_ptr = NULL; diff --git a/include/openssl/bytestring.h b/include/openssl/bytestring.h index c59bb82dc50..20bd22bd88a 100644 --- a/include/openssl/bytestring.h +++ b/include/openssl/bytestring.h @@ -58,17 +58,20 @@ struct cbs_st { // CBS_init sets |cbs| to point to |data|. It does not take ownership of // |data|. -OPENSSL_EXPORT void CBS_init(CBS *cbs, const uint8_t *data, size_t len); +OPENSSL_INLINE void CBS_init(CBS *cbs, const uint8_t *data, size_t len) { + cbs->data = data; + cbs->len = len; +} // CBS_skip advances |cbs| by |len| bytes. It returns one on success and zero // otherwise. OPENSSL_EXPORT int CBS_skip(CBS *cbs, size_t len); // CBS_data returns a pointer to the contents of |cbs|. -OPENSSL_EXPORT const uint8_t *CBS_data(const CBS *cbs); +OPENSSL_INLINE const uint8_t *CBS_data(const CBS *cbs) { return cbs->data; } // CBS_len returns the number of bytes remaining in |cbs|. -OPENSSL_EXPORT size_t CBS_len(const CBS *cbs); +OPENSSL_INLINE size_t CBS_len(const CBS *cbs) { return cbs->len; } // CBS_stow copies the current contents of |cbs| into |*out_ptr| and // |*out_len|. If |*out_ptr| is not NULL, the contents are freed with