mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1249174 (part 4) - Don't store unused XPTHeader fields in memory. r=khuey.
This requires merging XPT_DoHeaderPrologue() and XPT_DoHeader(), which is straightforward. This reduces "xpti-working-set" by 16 KiB on 64-bit platforms. --HG-- extra : rebase_source : 74510d6aefe8adc20064bee2c729d7a55fe4b58a
This commit is contained in:
parent
e9cbb90ad3
commit
52f54b61b3
@ -45,25 +45,29 @@ DoParamDescriptor(XPTArena *arena, XPTCursor *cursor, XPTParamDescriptor *pd,
|
||||
/***************************************************************************/
|
||||
|
||||
XPT_PUBLIC_API(PRBool)
|
||||
XPT_DoHeaderPrologue(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp, uint32_t * ide_offset)
|
||||
XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp)
|
||||
{
|
||||
unsigned int i;
|
||||
uint32_t file_length = 0;
|
||||
uint32_t ide_offset;
|
||||
|
||||
XPTHeader* header = XPT_NEWZAP(arena, XPTHeader);
|
||||
if (!header)
|
||||
return PR_FALSE;
|
||||
*headerp = header;
|
||||
|
||||
for (i = 0; i < sizeof(header->magic); i++) {
|
||||
if (!XPT_Do8(cursor, &header->magic[i]))
|
||||
uint8_t magic[16];
|
||||
for (i = 0; i < sizeof(magic); i++) {
|
||||
if (!XPT_Do8(cursor, &magic[i]))
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (strncmp((const char*)header->magic, XPT_MAGIC, 16) != 0) {
|
||||
if (strncmp((const char*)magic, XPT_MAGIC, 16) != 0) {
|
||||
/* Require that the header contain the proper magic */
|
||||
fprintf(stderr,
|
||||
"libxpt: bad magic header in input file; "
|
||||
"found '%s', expected '%s'\n",
|
||||
header->magic, XPT_MAGIC_STRING);
|
||||
magic, XPT_MAGIC_STRING);
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
@ -77,43 +81,31 @@ XPT_DoHeaderPrologue(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp, ui
|
||||
* number. We must set the header state thusly and return.
|
||||
*/
|
||||
header->num_interfaces = 0;
|
||||
header->file_length = 0;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
if (!XPT_Do16(cursor, &header->num_interfaces) ||
|
||||
!XPT_Do32(cursor, &header->file_length) ||
|
||||
(ide_offset != NULL && !XPT_Do32(cursor, ide_offset))) {
|
||||
!XPT_Do32(cursor, &file_length) ||
|
||||
!XPT_Do32(cursor, &ide_offset)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
XPT_PUBLIC_API(PRBool)
|
||||
XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp)
|
||||
{
|
||||
XPTHeader * header;
|
||||
uint32_t ide_offset;
|
||||
int i;
|
||||
|
||||
if (!XPT_DoHeaderPrologue(arena, cursor, headerp, &ide_offset))
|
||||
return PR_FALSE;
|
||||
header = *headerp;
|
||||
/*
|
||||
* Make sure the file length reported in the header is the same size as
|
||||
* as our buffer unless it is zero (not set)
|
||||
*/
|
||||
if (header->file_length != 0 &&
|
||||
cursor->state->pool_allocated < header->file_length) {
|
||||
if (file_length != 0 &&
|
||||
cursor->state->pool_allocated < file_length) {
|
||||
fputs("libxpt: File length in header does not match actual length. File may be corrupt\n",
|
||||
stderr);
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (!XPT_Do32(cursor, &header->data_pool))
|
||||
uint32_t data_pool;
|
||||
if (!XPT_Do32(cursor, &data_pool))
|
||||
return PR_FALSE;
|
||||
|
||||
XPT_SetDataOffset(cursor->state, header->data_pool);
|
||||
XPT_SetDataOffset(cursor->state, data_pool);
|
||||
|
||||
if (header->num_interfaces) {
|
||||
header->interface_directory =
|
||||
|
@ -56,13 +56,17 @@ typedef struct nsID nsID;
|
||||
* Every XPCOM typelib file begins with a header.
|
||||
*/
|
||||
struct XPTHeader {
|
||||
uint8_t magic[16];
|
||||
// Some of these fields exists in the on-disk format but don't need to be
|
||||
// stored in memory (other than very briefly, which can be done with local
|
||||
// variables).
|
||||
|
||||
//uint8_t magic[16];
|
||||
uint8_t major_version;
|
||||
uint8_t minor_version;
|
||||
uint16_t num_interfaces;
|
||||
uint32_t file_length;
|
||||
//uint32_t file_length;
|
||||
XPTInterfaceDirectoryEntry *interface_directory;
|
||||
uint32_t data_pool;
|
||||
//uint32_t data_pool;
|
||||
};
|
||||
|
||||
#define XPT_MAGIC "XPCOM\nTypeLib\r\n\032"
|
||||
@ -71,15 +75,14 @@ struct XPTHeader {
|
||||
#define XPT_MAJOR_VERSION 0x01
|
||||
#define XPT_MINOR_VERSION 0x02
|
||||
|
||||
/* Any file with a major version number of XPT_MAJOR_INCOMPATIBLE_VERSION
|
||||
/* Any file with a major version number of XPT_MAJOR_INCOMPATIBLE_VERSION
|
||||
* or higher is to be considered incompatible by this version of xpt and
|
||||
* we will refuse to read it. We will return a header with magic, major and
|
||||
* minor versions set from the file. num_interfaces and file_length will be
|
||||
* set to zero to confirm our inability to read the file; i.e. even if some
|
||||
* client of this library gets out of sync with us regarding the agreed upon
|
||||
* value for XPT_MAJOR_INCOMPATIBLE_VERSION, anytime num_interfaces and
|
||||
* file_length are both zero we *know* that this library refused to read the
|
||||
* file due to version imcompatibility.
|
||||
* minor versions set from the file. num_interfaces will be set to zero to
|
||||
* confirm our inability to read the file; i.e. even if some client of this
|
||||
* library gets out of sync with us regarding the agreed upon value for
|
||||
* XPT_MAJOR_INCOMPATIBLE_VERSION, anytime num_interfaces is zero we *know*
|
||||
* that this library refused to read the file due to version incompatibility.
|
||||
*/
|
||||
#define XPT_MAJOR_INCOMPATIBLE_VERSION 0x02
|
||||
|
||||
|
@ -41,8 +41,6 @@ XPT_Do16(XPTCursor *cursor, uint16_t *u16p);
|
||||
extern XPT_PUBLIC_API(PRBool)
|
||||
XPT_Do8(XPTCursor *cursor, uint8_t *u8p);
|
||||
|
||||
extern XPT_PUBLIC_API(PRBool)
|
||||
XPT_DoHeaderPrologue(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp, uint32_t * ide_offset);
|
||||
extern XPT_PUBLIC_API(PRBool)
|
||||
XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user