aboutsummaryrefslogtreecommitdiff
path: root/ltable.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* DetailsRoberto Ierusalimschy2025-01-161-4/+4
| | | | New year (2024->2025), typos in comments
* Fixed conversion warnings from clangRoberto Ierusalimschy2025-01-141-2/+2
| | | | | Plus some other details. (Option '-Wuninitialized' was removed from the makefile because it is already enabled by -Wall.)
* Detail (debugging aid)Roberto Ierusalimschy2025-01-061-0/+2
| | | | | When compiling with option HARDMEMTESTS, every creation of a new key in a table forces an emergency GC.
* Small optimization in 'luaH_psetshortstr'Roberto Ierusalimschy2024-12-281-18/+63
| | | | | | | Do not optimize only for table updates (key already present). Creation of new short keys in new tables can be quite common in programs that create lots of small tables, for instance with constructors like {x=e1,y=e2}.
* Scanner and parser use different tables for constantsRoberto Ierusalimschy2024-12-171-10/+1
| | | | | | | | | | Moreover, each function being parsed has its own table. The code is cleaner when each table is used for one specific purpose: The scanner uses its table to anchor and unify strings, mapping strings to themselves; the parser uses it to reuse constants in the code, mapping constants to their indices in the constant table. A different table for each task avoids false collisions.
* Rehash reinserts elements with "lighter" functionsRoberto Ierusalimschy2024-12-051-17/+33
| | | | | | | | | | | | When reinserting elements into a table during a rehash, the code does not need to invoke all the complexity of a full 'luaH_set': - The table has space for all keys. - The key cannot exist in the new hash. - The keys are valid (not NaN nor nil). - The keys are normalized (1.0 -> 1). - The values cannot be nil. - No barrier needed (the table already pointed to the key and value).
* Refactoring of 'luaH_newkey'Roberto Ierusalimschy2024-12-051-53/+77
| | | | | Function broke in two and some checks moved to the caller. (We may want to call it without the checks.)
* New way to keep hints for table lengthRoberto Ierusalimschy2024-11-291-198/+100
| | | | | | | | | | Instead of using 'alimit' for keeping the size of the array and at the same time being a hint for '#t', a table now keeps these two values separate. The Table structure has a field 'asize' with the size of the array, while the length hint is kept in the array itself. That way, tables with no array part waste no space with that field. Moreover, the space for the hint may have zero cost for small arrays, if the array of tags plus the hint still fits in a single word.
* Avoid an extra call to 'concretesize' in 'resizearray'Roberto Ierusalimschy2024-11-271-5/+5
|
* 'objsize' returns 'l_mem'Roberto Ierusalimschy2024-11-151-2/+3
| | | | Sums of size_t may not fit in a size_t.
* Dummy node has a non-nil keyRoberto Ierusalimschy2024-11-151-25/+28
| | | | | That allows 'getfreepos' to treat it like a regular hash part that has a deleted entry.
* Add extra size when resizing tables with deleted keysRoberto Ierusalimschy2024-11-141-5/+21
| | | | | | | | Without this extra space, sequences of insertions/deletions (and some other uses) can have unpexpected low performances. See the added tests for an example, and *Mathematical Models to Analyze Lua Hybrid Tables and Why They Need a Fix* (Martínez, Nicaud, Rotondo; arXiv:2208.13602v2) for detais.
* New rule for size of array partRoberto Ierusalimschy2024-11-131-7/+20
| | | | | | | | Array part needs 1/3 of its elements filled, instead of 1/2. Array entries use ~1/3 the memory of hash entries, so this new rule still ensures that array parts do not use more memory than keeping the values in the hash, while allowing more uses of the array part, which is more efficient than the hash.
* New structure to count keys in a table for rehashingRoberto Ierusalimschy2024-10-281-50/+65
|
* Table rehash can resize only the hash partRoberto Ierusalimschy2024-10-281-14/+19
| | | | | | | If there are no integer keys outside the array part, there is no reason to resize it, saving the time to count its elements. Moreover, assignments to non-integer keys will not collapse a table created with 'table.create'.
* Always use unsigned int for indexing table-arraysRoberto Ierusalimschy2024-10-241-4/+4
|
* 'objsize' broke in smaller piecesRoberto Ierusalimschy2024-09-301-0/+12
|
* Avoid Microsoft warningRoberto Ierusalimschy2024-09-191-1/+2
| | | | | > warning C4334: '<<': result of 32-bit shift implicitly converted to > 64 bits (was 64-bit shift intended?)
* Added gcc option '-Wconversion'Roberto Ierusalimschy2024-07-271-33/+34
| | | | | No warnings for standard numerical types. Still pending alternative numerical types.
* 'isIT'/'isOT' turned from macros to functionsRoberto Ierusalimschy2024-06-271-1/+1
|
* Encoding of table indices (hres) must use C indicesRoberto Ierusalimschy2024-06-101-6/+6
| | | | | As the encoding of array indices is (~index), 0 is encoded as -1 and INT_MAX is encoded as INT_MIN.
* Yet another representation for arraysRoberto Ierusalimschy2024-04-051-23/+44
| | | | | | This "linear" representation (see ltable.h for details) has worse locality than cells, but the simpler access code seems to compensate that.
* Some 'unsigned int' changed to 'unsigned'Roberto Ierusalimschy2024-03-221-10/+10
| | | | | 'unsigned int' is too long sometimes. (We already write 'long' instead of 'long int'...)
* 'luaH_get' functions return tag of the resultRoberto Ierusalimschy2024-03-211-18/+30
| | | | | | | Undoing previous commit. Returning TValue increases code size without any visible gains. Returning the tag is a little simpler than returning a special code (HOK/HNOTFOUND) and the tag is useful by itself in some cases.
* 'luaH_get' functions return 'TValue'Roberto Ierusalimschy2024-03-181-35/+18
| | | | | | Instead of receiving a parameter telling them where to put the result of the query, these functions return the TValue directly. (That is, they return a structure.)
* Removed "bulk operations"Roberto Ierusalimschy2024-03-151-13/+4
| | | | Negligible performance gains don't justify extra complexity.
* Added "bulk operations" to arraysRoberto Ierusalimschy2024-03-151-15/+42
| | | | | A few operations on arrays can be performed "in bulk", treating all tags of a cell as a simple (or a few) word(s).
* Fixed warnings from different compilersRoberto Ierusalimschy2024-02-151-1/+2
|
* Field 'lastfree' changed (back) to 'Node *'Roberto Ierusalimschy2024-02-071-14/+16
| | | | | Due to allignment, it is already using the space of a pointer, and a pointer generates slightly simpler code.
* Better handling of size limit when resizing a tableRoberto Ierusalimschy2024-02-071-4/+13
| | | | | | | | Avoid silent conversions from int to unsigned int when calling 'luaH_resize'; avoid silent conversions from lua_Integer to int in 'table.create'; MAXASIZE corrected for the new implementation of arrays; 'luaH_resize' checks explicitly whether new size respects MAXASIZE. (Even constructors were bypassing that check.)
* Small optimization in 'luaH_psetint'Roberto Ierusalimschy2024-01-251-1/+1
| | | | | | It is quite common to write to empty but existing cells in the array part of a table, so 'luaH_psetint' checks for the common case that the table doesn't have a newindex metamethod to complete the write.
* Optimizations for 'lua_rawgeti' and 'lua_rawseti'Roberto Ierusalimschy2024-01-121-18/+37
| | | | | | 'lua_rawgeti' now uses "fast track"; 'lua_rawseti' still calls 'luaH_setint', but the latter was recoded to avoid extra overhead when writing to the array part after 'alimit'.
* Simpler coding for new representation for arraysRoberto Ierusalimschy2023-11-241-19/+27
| | | | | With the tags comming first in a cell, we can define the whole cell as a C type and let C do part of the address computations.
* Merge branch 'newarray' into nextversionRoberto Ierusalimschy2023-11-071-84/+244
|\
| * Merge branch 'master' into newarrayRoberto Ierusalimschy2023-11-031-2/+3
| |\
| * | Full implementation of new representation for arraysRoberto Ierusalimschy2023-11-031-9/+37
| | |
| * | Full abstraction for representation of array valuesRoberto Ierusalimschy2023-10-301-56/+60
| | |
| * | Avoid direct accesses to the array part of a tableRoberto Ierusalimschy2023-10-271-49/+79
| | |
| * | Some cleaning in the new table APIRoberto Ierusalimschy2023-05-161-50/+52
| | |
| * | New table API for 'set' functionsRoberto Ierusalimschy2023-05-161-20/+100
| | |
| * | Towards a new implementation of arraysRoberto Ierusalimschy2023-05-151-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The array part of a table wastes too much space, due to padding. To avoid that, we need to store values in the array as something different from a TValue. Therefore, the API for table access should not assume that any value in a table lives in a *TValue. This commit is the first step to remove that assumption: functions luaH_get*, instead of returning a *TValue where the value lives, receive a *TValue where to put the value being accessed. (We still have to change the luaH_set* functions.)
* | | Merge branch 'master' into nextversionRoberto Ierusalimschy2023-11-071-11/+25
|\ \ \ | | |/ | |/|
| * | Simpler test in 'luaH_getint'Roberto Ierusalimschy2023-10-261-11/+25
| | | | | | | | | | | | | | | The test whether key is inside the array part of a table uses a bit trick to avoid computing the real size of the array part.
* | | Merge branch 'master' into nextversionRoberto Ierusalimschy2023-06-221-1/+4
|\| |
| * | DetailsRoberto Ierusalimschy2023-05-151-1/+2
| |/ | | | | | | | | - Better comments about short strings in opcodes. - luaH_newkey made static.
| * Corrected support for 16-bit systemsRoberto Ierusalimschy2023-03-091-0/+2
| | | | | | | | | | We still need access to a 16-bit system to correctly test these changes.
* | Tables have a 'lastfree' information only when neededRoberto Ierusalimschy2022-11-011-15/+65
|/ | | | | Only tables with some minimum number of entries in their hash part have a 'lastfree' field, kept in a header before the node vector.
* Removed test function 'luaH_isdummy'Roberto Ierusalimschy2022-10-211-2/+0
| | | | It was not being used anywhere.
* DetailsRoberto Ierusalimschy2022-10-191-2/+2
| | | | Some cast operations rewritten to use respective macros.
* Main 'mainposition' replaced by 'mainpositionTV'Roberto Ierusalimschy2021-11-251-19/+16
| | | | | Handle values in table keys as the special cases they are, and not the other way around.