Skip to content

Commit

Permalink
Making EmbeddedAssemblies a static type
Browse files Browse the repository at this point in the history
In process to remove object instances for a slightly faster startup
  • Loading branch information
grendello committed Nov 7, 2024
1 parent a299f4c commit 8187508
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 89 deletions.
20 changes: 10 additions & 10 deletions src/native/monodroid/embedded-assemblies-zip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ EmbeddedAssemblies::zip_load_assembly_store_entries (std::vector<uint8_t> const&
}

void
EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unused]] monodroid_should_register should_register)
EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unused]] monodroid_should_register should_register) noexcept
{
uint32_t cd_offset;
uint32_t cd_size;
Expand Down Expand Up @@ -412,7 +412,7 @@ EmbeddedAssemblies::set_debug_entry_data (XamarinAndroidBundledAssembly &entry,
}

bool
EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_size, uint16_t& cd_entries)
EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_size, uint16_t& cd_entries) noexcept
{
// The simplest case - no file comment
off_t ret = ::lseek (fd, -ZIP_EOCD_LEN, SEEK_END);
Expand Down Expand Up @@ -478,7 +478,7 @@ EmbeddedAssemblies::zip_read_cd_info (int fd, uint32_t& cd_offset, uint32_t& cd_
}

bool
EmbeddedAssemblies::zip_adjust_data_offset (int fd, ZipEntryLoadState &state)
EmbeddedAssemblies::zip_adjust_data_offset (int fd, ZipEntryLoadState &state) noexcept
{
static constexpr size_t LH_FILE_NAME_LENGTH_OFFSET = 26uz;
static constexpr size_t LH_EXTRA_LENGTH_OFFSET = 28uz;
Expand Down Expand Up @@ -530,7 +530,7 @@ EmbeddedAssemblies::zip_adjust_data_offset (int fd, ZipEntryLoadState &state)

template<size_t BufSize>
bool
EmbeddedAssemblies::zip_extract_cd_info (std::array<uint8_t, BufSize> const& buf, uint32_t& cd_offset, uint32_t& cd_size, uint16_t& cd_entries)
EmbeddedAssemblies::zip_extract_cd_info (std::array<uint8_t, BufSize> const& buf, uint32_t& cd_offset, uint32_t& cd_size, uint16_t& cd_entries) noexcept
{
constexpr size_t EOCD_TOTAL_ENTRIES_OFFSET = 10uz;
constexpr size_t EOCD_CD_SIZE_OFFSET = 12uz;
Expand Down Expand Up @@ -558,7 +558,7 @@ EmbeddedAssemblies::zip_extract_cd_info (std::array<uint8_t, BufSize> const& buf

template<class T>
force_inline bool
EmbeddedAssemblies::zip_ensure_valid_params (T const& buf, size_t index, size_t to_read) const noexcept
EmbeddedAssemblies::zip_ensure_valid_params (T const& buf, size_t index, size_t to_read) noexcept
{
if (index + to_read > buf.size ()) {
log_error (LOG_ASSEMBLY, "Buffer too short to read %u bytes of data", to_read);
Expand All @@ -570,7 +570,7 @@ EmbeddedAssemblies::zip_ensure_valid_params (T const& buf, size_t index, size_t

template<ByteArrayContainer T>
bool
EmbeddedAssemblies::zip_read_field (T const& src, size_t source_index, uint16_t& dst) const noexcept
EmbeddedAssemblies::zip_read_field (T const& src, size_t source_index, uint16_t& dst) noexcept
{
if (!zip_ensure_valid_params (src, source_index, sizeof (dst))) {
return false;
Expand All @@ -583,7 +583,7 @@ EmbeddedAssemblies::zip_read_field (T const& src, size_t source_index, uint16_t&

template<ByteArrayContainer T>
bool
EmbeddedAssemblies::zip_read_field (T const& src, size_t source_index, uint32_t& dst) const noexcept
EmbeddedAssemblies::zip_read_field (T const& src, size_t source_index, uint32_t& dst) noexcept
{
if (!zip_ensure_valid_params (src, source_index, sizeof (dst))) {
return false;
Expand All @@ -600,7 +600,7 @@ EmbeddedAssemblies::zip_read_field (T const& src, size_t source_index, uint32_t&

template<ByteArrayContainer T>
bool
EmbeddedAssemblies::zip_read_field (T const& src, size_t source_index, std::array<uint8_t, 4>& dst_sig) const noexcept
EmbeddedAssemblies::zip_read_field (T const& src, size_t source_index, std::array<uint8_t, 4>& dst_sig) noexcept
{
if (!zip_ensure_valid_params (src, source_index, dst_sig.size ())) {
return false;
Expand All @@ -612,7 +612,7 @@ EmbeddedAssemblies::zip_read_field (T const& src, size_t source_index, std::arra

template<ByteArrayContainer T>
bool
EmbeddedAssemblies::zip_read_field (T const& buf, size_t index, size_t count, dynamic_local_string<SENSIBLE_PATH_MAX>& characters) const noexcept
EmbeddedAssemblies::zip_read_field (T const& buf, size_t index, size_t count, dynamic_local_string<SENSIBLE_PATH_MAX>& characters) noexcept
{
if (!zip_ensure_valid_params (buf, index, count)) {
return false;
Expand All @@ -623,7 +623,7 @@ EmbeddedAssemblies::zip_read_field (T const& buf, size_t index, size_t count, dy
}

bool
EmbeddedAssemblies::zip_read_entry_info (std::vector<uint8_t> const& buf, dynamic_local_string<SENSIBLE_PATH_MAX>& file_name, ZipEntryLoadState &state)
EmbeddedAssemblies::zip_read_entry_info (std::vector<uint8_t> const& buf, dynamic_local_string<SENSIBLE_PATH_MAX>& file_name, ZipEntryLoadState &state) noexcept
{
constexpr size_t CD_COMPRESSION_METHOD_OFFSET = 10uz;
constexpr size_t CD_UNCOMPRESSED_SIZE_OFFSET = 24uz;
Expand Down
14 changes: 6 additions & 8 deletions src/native/monodroid/embedded-assemblies.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class MonoGuidString final
char *guid = nullptr;
};

void EmbeddedAssemblies::set_assemblies_prefix (const char *prefix)
void EmbeddedAssemblies::set_assemblies_prefix (const char *prefix) noexcept
{
if (assemblies_prefix_override != nullptr)
delete[] assemblies_prefix_override;
Expand Down Expand Up @@ -912,7 +912,7 @@ EmbeddedAssemblies::md_mmap_apk_file (int fd, uint32_t offset, size_t size, cons
}

void
EmbeddedAssemblies::gather_bundled_assemblies_from_apk (const char* apk, monodroid_should_register should_register)
EmbeddedAssemblies::gather_bundled_assemblies_from_apk (const char* apk, monodroid_should_register should_register) noexcept
{
int fd;

Expand Down Expand Up @@ -1284,12 +1284,10 @@ EmbeddedAssemblies::register_from_filesystem (const char *lib_dir_path,bool look
}

auto register_fn =
application_config.have_assembly_store ? std::mem_fn (&EmbeddedAssemblies::maybe_register_blob_from_filesystem) :
application_config.have_assembly_store ? &EmbeddedAssemblies::maybe_register_blob_from_filesystem :
(look_for_mangled_names ?
std::mem_fn (&EmbeddedAssemblies::maybe_register_assembly_from_filesystem<true>) :
std::mem_fn (&EmbeddedAssemblies::maybe_register_assembly_from_filesystem<false>
)
);
&EmbeddedAssemblies::maybe_register_assembly_from_filesystem<true> :
&EmbeddedAssemblies::maybe_register_assembly_from_filesystem<false>);

size_t assembly_count = 0uz;
do {
Expand Down Expand Up @@ -1334,7 +1332,7 @@ EmbeddedAssemblies::register_from_filesystem (const char *lib_dir_path,bool look
}

// We get `true` if it's time to terminate
if (register_fn (this, should_register, assembly_count, cur, state)) {
if (register_fn (should_register, assembly_count, cur, state)) {
break;
}
} while (true);
Expand Down
Loading

0 comments on commit 8187508

Please sign in to comment.