mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 15:02:42 +01:00
Use Value::misc to store strings
This allows strings < 23 characters (up from 16) to be stored directly in Value. On a NixOS 19.03 system configuration evaluation, this allows 1060588 out of 1189295 (89%) strings to be stored in Value.
This commit is contained in:
parent
742a8046de
commit
a38a7b495c
4 changed files with 25 additions and 12 deletions
|
|
@ -12,7 +12,7 @@ namespace nix {
|
|||
Bindings structure. */
|
||||
Ptr<Bindings> Bindings::allocBindings(size_t capacity)
|
||||
{
|
||||
if (capacity >= 1UL << Object::miscBits)
|
||||
if (capacity >= 1UL << Object::miscBytes * 8)
|
||||
throw Error("attribute set of size %d is too big", capacity);
|
||||
return gc.alloc<Bindings>(Bindings::wordsFor(capacity), capacity);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -497,10 +497,9 @@ LocalNoInline(void addErrorPrefix(Error & e, const char * s, const string & s2,
|
|||
void mkString(Value & v, const char * s)
|
||||
{
|
||||
auto len = strlen(s); // FIXME: only need to know if > short
|
||||
if (len < WORD_SIZE * 2) {
|
||||
strcpy((char *) &v.string, s);
|
||||
v.type = tShortString;
|
||||
} else
|
||||
if (len < WORD_SIZE * 2 + Object::miscBytes)
|
||||
v.setShortString(s);
|
||||
else
|
||||
mkStringNoCopy(v, dupString(s));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,17 +51,16 @@ struct Object
|
|||
friend class GC;
|
||||
|
||||
public:
|
||||
constexpr static unsigned int miscBits = 58;
|
||||
|
||||
private:
|
||||
unsigned long misc:58;
|
||||
constexpr static size_t miscBytes = 7;
|
||||
|
||||
public: // FIXME
|
||||
Tag type:5;
|
||||
Tag type:7;
|
||||
|
||||
private:
|
||||
bool marked:1;
|
||||
|
||||
unsigned long misc:56;
|
||||
|
||||
void unmark()
|
||||
{
|
||||
marked = false;
|
||||
|
|
@ -69,7 +68,7 @@ private:
|
|||
|
||||
protected:
|
||||
|
||||
Object(Tag type, unsigned long misc) : misc(misc), type(type), marked(false) { }
|
||||
Object(Tag type, unsigned long misc) : type(type), marked(false), misc(misc) { }
|
||||
|
||||
bool isMarked()
|
||||
{
|
||||
|
|
@ -90,6 +89,11 @@ protected:
|
|||
{
|
||||
return misc;
|
||||
}
|
||||
|
||||
char * getMiscData() const
|
||||
{
|
||||
return ((char *) this) + 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
#include "symbol-table.hh"
|
||||
#include "gc.hh"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace nix {
|
||||
|
||||
class Bindings;
|
||||
|
|
@ -203,10 +205,18 @@ public:
|
|||
return type == tShortString || type == tLongString;
|
||||
}
|
||||
|
||||
void setShortString(const char * s)
|
||||
{
|
||||
// FIXME: can't use strcpy here because gcc flags it as a
|
||||
// buffer overflow on 'misc'.
|
||||
memcpy(getMiscData(), s, strlen(s) + 1);
|
||||
type = tShortString;
|
||||
}
|
||||
|
||||
const char * getString() const
|
||||
{
|
||||
if (type == tShortString)
|
||||
return (const char *) &string;
|
||||
return getMiscData();
|
||||
else
|
||||
return string._s;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue