mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
Use less c_str() in the evaluator, and other cleanups
It is better to avoid null termination for performance and memory safety, wherever possible. These are good cleanups extracted from the Pascal String work that we can land by themselves first, shrinking the diff in that PR. Co-Authored-By: Aspen Smith <root@gws.fyi> Co-Authored-By: Sergei Zimmerman <sergei@zimmerman.foo>
This commit is contained in:
parent
2d83bc6b83
commit
bd42092873
16 changed files with 64 additions and 38 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "nix/expr/value.hh"
|
||||
|
||||
#include "nix/store/tests/libstore.hh"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
@ -22,4 +23,21 @@ TEST_F(ValueTest, vInt)
|
|||
ASSERT_EQ(true, vInt.isValid());
|
||||
}
|
||||
|
||||
TEST_F(ValueTest, staticString)
|
||||
{
|
||||
Value vStr1;
|
||||
Value vStr2;
|
||||
vStr1.mkStringNoCopy("foo");
|
||||
vStr2.mkStringNoCopy("foo");
|
||||
|
||||
auto sd1 = vStr1.string_view();
|
||||
auto sd2 = vStr2.string_view();
|
||||
|
||||
// The strings should be the same
|
||||
ASSERT_EQ(sd1, sd2);
|
||||
|
||||
// The strings should also be backed by the same (static) allocation
|
||||
ASSERT_EQ(sd1.data(), sd2.data());
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue