File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,12 @@ class LIBSCRATCHCPP_EXPORT List : public Entity
4040 /* ! Returns a pointer to the raw list data. */
4141 inline ValueData *data () const { return m_dataPtr->data (); }
4242
43+ /* !
44+ * Returns a pointer to the list size.
45+ * \note This is used internally by compiled code for various optimizations.
46+ */
47+ inline size_t *sizePtr () { return &m_size; }
48+
4349 /* ! Returns the list size. */
4450 inline size_t size () const { return m_size; }
4551
Original file line number Diff line number Diff line change @@ -57,6 +57,31 @@ TEST(ListTest, Data)
5757 ASSERT_EQ (&data[4 ], &list[4 ]);
5858}
5959
60+ TEST (ListTest, SizePtr)
61+ {
62+ List list (" " , " test list" );
63+ ASSERT_TRUE (list.sizePtr ());
64+ ASSERT_EQ (*list.sizePtr (), 0 );
65+ ASSERT_TRUE (list.empty ());
66+
67+ list.append (" Lorem" );
68+ list.append (" ipsum" );
69+ ASSERT_EQ (*list.sizePtr (), 2 );
70+ ASSERT_FALSE (list.empty ());
71+
72+ list.append (" dolor" );
73+ ASSERT_EQ (*list.sizePtr (), 3 );
74+ ASSERT_FALSE (list.empty ());
75+
76+ list.removeAt (0 );
77+ ASSERT_EQ (*list.sizePtr (), 2 );
78+ ASSERT_FALSE (list.empty ());
79+
80+ *list.sizePtr () = 100 ;
81+ ASSERT_EQ (*list.sizePtr (), 100 );
82+ ASSERT_EQ (list.size (), 100 );
83+ }
84+
6085TEST (ListTest, Size)
6186{
6287 List list (" " , " test list" );
You can’t perform that action at this time.
0 commit comments