Pbuf flag test size and speed optimalisation (helping a dumb compiler).

This commit is contained in:
christiaans 2006-03-28 15:06:33 +00:00
parent 39f8538776
commit d9b4ab1658

View File

@ -464,16 +464,18 @@ pbuf_realloc(struct pbuf *p, u16_t new_len)
u8_t u8_t
pbuf_header(struct pbuf *p, s16_t header_size_increment) pbuf_header(struct pbuf *p, s16_t header_size_increment)
{ {
u16_t flags;
void *payload; void *payload;
LWIP_ASSERT("p != NULL", p != NULL); LWIP_ASSERT("p != NULL", p != NULL);
if ((header_size_increment == 0) || (p == NULL)) return 0; if ((header_size_increment == 0) || (p == NULL)) return 0;
flags = p->flags;
/* remember current payload pointer */ /* remember current payload pointer */
payload = p->payload; payload = p->payload;
/* pbuf types containing payloads? */ /* pbuf types containing payloads? */
if (p->flags == PBUF_FLAG_RAM || p->flags == PBUF_FLAG_POOL) { if (flags == PBUF_FLAG_RAM || flags == PBUF_FLAG_POOL) {
/* set new payload pointer */ /* set new payload pointer */
p->payload = (u8_t *)p->payload - header_size_increment; p->payload = (u8_t *)p->payload - header_size_increment;
/* boundary check fails? */ /* boundary check fails? */
@ -487,7 +489,7 @@ pbuf_header(struct pbuf *p, s16_t header_size_increment)
return 1; return 1;
} }
/* pbuf types refering to external payloads? */ /* pbuf types refering to external payloads? */
} else if (p->flags == PBUF_FLAG_REF || p->flags == PBUF_FLAG_ROM) { } else if (flags == PBUF_FLAG_REF || flags == PBUF_FLAG_ROM) {
/* hide a header in the payload? */ /* hide a header in the payload? */
if ((header_size_increment < 0) && (header_size_increment - p->len <= 0)) { if ((header_size_increment < 0) && (header_size_increment - p->len <= 0)) {
/* increase payload pointer */ /* increase payload pointer */
@ -544,6 +546,7 @@ pbuf_header(struct pbuf *p, s16_t header_size_increment)
u8_t u8_t
pbuf_free(struct pbuf *p) pbuf_free(struct pbuf *p)
{ {
u16_t flags;
struct pbuf *q; struct pbuf *q;
u8_t count; u8_t count;
SYS_ARCH_DECL_PROTECT(old_level); SYS_ARCH_DECL_PROTECT(old_level);
@ -579,15 +582,16 @@ pbuf_free(struct pbuf *p)
/* remember next pbuf in chain for next iteration */ /* remember next pbuf in chain for next iteration */
q = p->next; q = p->next;
LWIP_DEBUGF( PBUF_DEBUG | 2, ("pbuf_free: deallocating %p\n", (void *)p)); LWIP_DEBUGF( PBUF_DEBUG | 2, ("pbuf_free: deallocating %p\n", (void *)p));
flags = p->flags;
/* is this a pbuf from the pool? */ /* is this a pbuf from the pool? */
if (p->flags == PBUF_FLAG_POOL) { if (flags == PBUF_FLAG_POOL) {
p->len = p->tot_len = PBUF_POOL_BUFSIZE; p->len = p->tot_len = PBUF_POOL_BUFSIZE;
p->payload = (void *)((u8_t *)p + sizeof(struct pbuf)); p->payload = (void *)((u8_t *)p + sizeof(struct pbuf));
PBUF_POOL_FREE(p); PBUF_POOL_FREE(p);
/* is this a ROM or RAM referencing pbuf? */ /* is this a ROM or RAM referencing pbuf? */
} else if (p->flags == PBUF_FLAG_ROM || p->flags == PBUF_FLAG_REF) { } else if (flags == PBUF_FLAG_ROM || flags == PBUF_FLAG_REF) {
memp_free(MEMP_PBUF, p); memp_free(MEMP_PBUF, p);
/* p->flags == PBUF_FLAG_RAM */ /* flags == PBUF_FLAG_RAM */
} else { } else {
mem_free(p); mem_free(p);
} }