Skip to content

Commit a8d35e5

Browse files
committed
Merge pull request #1586 from pguyot/w11/optimize-atoms
Add support for atoms longer than 255 bytes (but less than 256 chars) See #1536 These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents fb85fc1 + f260b37 commit a8d35e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+934
-1125
lines changed

src/libAtomVM/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ project (libAtomVM)
2323

2424
set(HEADER_FILES
2525
atom.h
26-
atomshashtable.h
2726
atom_table.h
2827
avmpack.h
2928
bif.h
@@ -75,7 +74,6 @@ set(HEADER_FILES
7574

7675
set(SOURCE_FILES
7776
atom.c
78-
atomshashtable.c
7977
atom_table.c
8078
avmpack.c
8179
bif.c

src/libAtomVM/atom.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,17 @@ static void utoa10(unsigned int int_value, char *integer_string)
8787
integer_string[integer_string_len] = '\0';
8888
}
8989

90-
void atom_write_mfa(char *buf, size_t buf_size, AtomString module, AtomString function, unsigned int arity)
90+
void atom_write_mfa(char *buf, size_t buf_size, size_t module_name_len, const void *module_data, size_t function_name_len, const void *function_data, unsigned int arity)
9191
{
92-
size_t module_name_len = atom_string_len(module);
93-
memcpy(buf, atom_string_data(module), module_name_len);
92+
memcpy(buf, module_data, module_name_len);
9493

9594
buf[module_name_len] = ':';
9695

97-
size_t function_name_len = atom_string_len(function);
9896
if (UNLIKELY((module_name_len + 1 + function_name_len + 1 + 4 + 1 > buf_size))) {
9997
fprintf(stderr, "Insufficient room to write mfa.\n");
10098
AVM_ABORT();
10199
}
102-
memcpy(buf + module_name_len + 1, atom_string_data(function), function_name_len);
100+
memcpy(buf + module_name_len + 1, function_data, function_name_len);
103101

104102
buf[module_name_len + function_name_len + 1] = '/';
105103
utoa10(arity, buf + module_name_len + 1 + function_name_len + 1);

src/libAtomVM/atom.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern "C" {
4545
#define ATOM_STR(LENSTR, STR) (LENSTR STR)
4646

4747
typedef const void *AtomString;
48+
typedef uint32_t atom_index_t;
4849

4950
/**
5051
* @brief Gets a C string from an AtomString
@@ -98,11 +99,13 @@ static inline const void *atom_string_data(AtomString atom_str)
9899
* buffer size.
99100
* @param buf the buffer to write into
100101
* @param buf_size the amount of room in the buffer
101-
* @param module the module name
102-
* @param function the function name
102+
* @param module_name_len length of the module name
103+
* @param module_data the module name
104+
* @param function_name_len length of the function name
105+
* @param function_data the function name
103106
* @param arity the function arity
104107
*/
105-
void atom_write_mfa(char *buf, size_t buf_size, AtomString module, AtomString function, unsigned int arity);
108+
void atom_write_mfa(char *buf, size_t buf_size, size_t module_name_len, const void *module_data, size_t function_name_len, const void *function_data, unsigned int arity);
106109

107110
#ifdef __cplusplus
108111
}

0 commit comments

Comments
 (0)