Skip to content

Commit

Permalink
Inline CBS_init, CBS_data, and CBS_len
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Bob Beck <[email protected]>
Commit-Queue: David Benjamin <[email protected]>
(cherry picked from commit e202e51cb0912f36dafbd2e67cf04d6ec82f3180)
  • Loading branch information
davidben authored and skmcgrail committed Nov 25, 2024
1 parent b2f8875 commit f393d48
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
9 changes: 0 additions & 9 deletions crypto/bytestring/cbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions include/openssl/bytestring.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f393d48

Please sign in to comment.