[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-devel] pbuf_alloc optimization
From: |
Charles Landau |
Subject: |
[lwip-devel] pbuf_alloc optimization |
Date: |
Thu, 19 Feb 2009 10:10:40 -0800 |
User-agent: |
Thunderbird 2.0.0.19 (Macintosh/20081209) |
Looking at pbuf_alloc in LWIP 1.3, it could be made faster and smaller
with some judicious inlining:
pbuf.h:
static inline
struct pbuf * pbuf_alloc(pbuf_layer l, u16_t size, pbuf_type type)
{
unsigned int offset = 0;
switch (layer) {
case PBUF_TRANSPORT:
offset += PBUF_TRANSPORT_HLEN;
case PBUF_IP:
offset += PBUF_IP_HLEN;
etc.
}
switch (type) {
case PBUF_POOL:
return pbuf_alloc_pool(offset, size);
case PBUF_RAM:
return pbuf_alloc_ram(offset, size);
case PBUF_ROM:
case PBUF_REF:
return pbuf_alloc_romref(offset, size, type);
etc.
}
}
Since the layer and type parameters are always constant, the compiler
can optimize the call into a single call of pbuf_alloc_<type>,
eliminating the two switch's. I believe gcc is smart enough to do so.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lwip-devel] pbuf_alloc optimization,
Charles Landau <=