Skip to content

Commit 6e8f75a

Browse files
authored
Merge pull request livecode#6969 from runrevmark/bugfix-21993
[[ Bug 21993 ]] Tweak __MCName and __MCString layouts
2 parents e2a56b3 + fb7ab96 commit 6e8f75a

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

docs/notes/bugfix-21993.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Make name and string values more memory efficient

libfoundation/src/foundation-private.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,21 @@ struct __MCString: public __MCValue
257257
MCStringRef string;
258258
struct
259259
{
260+
#ifdef __32_BIT__
261+
uindex_t char_count;
262+
union
263+
{
264+
unichar_t *chars;
265+
char_t *native_chars;
266+
};
267+
double numeric_value;
268+
uindex_t capacity;
269+
/* The padding is here to ensure the size of the struct is 32-bytes
270+
* on all platforms. This ensures consistency between Win and UNIX
271+
* ABIs which have slightly different rules concerning double
272+
* alignment. */
273+
uint32_t __padding;
274+
#else
260275
uindex_t char_count;
261276
uindex_t capacity;
262277
union
@@ -265,6 +280,7 @@ struct __MCString: public __MCValue
265280
char_t *native_chars;
266281
};
267282
double numeric_value;
283+
#endif
268284
};
269285
};
270286
};
@@ -307,7 +323,6 @@ struct __MCName: public __MCValue
307323
uintptr_t next;
308324
uintptr_t key;
309325
MCStringRef string;
310-
hash_t hash;
311326
#endif
312327
};
313328

libfoundation/test/test_memory.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,30 @@ TEST(memory, information)
6565
_memory_malloc_size(48);
6666
_memory_malloc_size(64);
6767
}
68+
69+
TEST(memory, sizes)
70+
{
71+
#ifdef __32_BIT__
72+
EXPECT_EQ(sizeof(__MCNull), 8);
73+
EXPECT_EQ(sizeof(__MCBoolean), 8);
74+
EXPECT_EQ(sizeof(__MCNumber), 16);
75+
EXPECT_EQ(sizeof(__MCName), 24);
76+
EXPECT_EQ(sizeof(__MCString), 32);
77+
EXPECT_EQ(sizeof(__MCData), 20);
78+
EXPECT_EQ(sizeof(__MCArray), 16);
79+
EXPECT_EQ(sizeof(__MCList), 16);
80+
EXPECT_EQ(sizeof(__MCSet), 16);
81+
EXPECT_EQ(sizeof(__MCProperList), 16);
82+
#else
83+
EXPECT_EQ(sizeof(__MCNull), 8);
84+
EXPECT_EQ(sizeof(__MCBoolean), 8);
85+
EXPECT_EQ(sizeof(__MCNumber), 16);
86+
EXPECT_EQ(sizeof(__MCName), 32);
87+
EXPECT_EQ(sizeof(__MCString), 32);
88+
EXPECT_EQ(sizeof(__MCData), 24);
89+
EXPECT_EQ(sizeof(__MCArray), 24);
90+
EXPECT_EQ(sizeof(__MCList), 24);
91+
EXPECT_EQ(sizeof(__MCSet), 24);
92+
EXPECT_EQ(sizeof(__MCProperList), 24);
93+
#endif
94+
}

0 commit comments

Comments
 (0)