mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 23:12:44 +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. */
|
Bindings structure. */
|
||||||
Ptr<Bindings> Bindings::allocBindings(size_t capacity)
|
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);
|
throw Error("attribute set of size %d is too big", capacity);
|
||||||
return gc.alloc<Bindings>(Bindings::wordsFor(capacity), 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)
|
void mkString(Value & v, const char * s)
|
||||||
{
|
{
|
||||||
auto len = strlen(s); // FIXME: only need to know if > short
|
auto len = strlen(s); // FIXME: only need to know if > short
|
||||||
if (len < WORD_SIZE * 2) {
|
if (len < WORD_SIZE * 2 + Object::miscBytes)
|
||||||
strcpy((char *) &v.string, s);
|
v.setShortString(s);
|
||||||
v.type = tShortString;
|
else
|
||||||
} else
|
|
||||||
mkStringNoCopy(v, dupString(s));
|
mkStringNoCopy(v, dupString(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,17 +51,16 @@ struct Object
|
||||||
friend class GC;
|
friend class GC;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr static unsigned int miscBits = 58;
|
constexpr static size_t miscBytes = 7;
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned long misc:58;
|
|
||||||
|
|
||||||
public: // FIXME
|
public: // FIXME
|
||||||
Tag type:5;
|
Tag type:7;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool marked:1;
|
bool marked:1;
|
||||||
|
|
||||||
|
unsigned long misc:56;
|
||||||
|
|
||||||
void unmark()
|
void unmark()
|
||||||
{
|
{
|
||||||
marked = false;
|
marked = false;
|
||||||
|
|
@ -69,7 +68,7 @@ private:
|
||||||
|
|
||||||
protected:
|
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()
|
bool isMarked()
|
||||||
{
|
{
|
||||||
|
|
@ -90,6 +89,11 @@ protected:
|
||||||
{
|
{
|
||||||
return misc;
|
return misc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char * getMiscData() const
|
||||||
|
{
|
||||||
|
return ((char *) this) + 1;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
#include "symbol-table.hh"
|
#include "symbol-table.hh"
|
||||||
#include "gc.hh"
|
#include "gc.hh"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
class Bindings;
|
class Bindings;
|
||||||
|
|
@ -203,10 +205,18 @@ public:
|
||||||
return type == tShortString || type == tLongString;
|
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
|
const char * getString() const
|
||||||
{
|
{
|
||||||
if (type == tShortString)
|
if (type == tShortString)
|
||||||
return (const char *) &string;
|
return getMiscData();
|
||||||
else
|
else
|
||||||
return string._s;
|
return string._s;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue