$Revision$
$Date$

# Type str

One of our main goals was to make SER really fast. There are many functions across the server that need to work with strings. Usually these functions need to know string length. We wanted to avoid using of `strlen` because the function is relatively slow. It must scan the whole string and find the first occurrence of zero character. To avoid this, we created str type. The type has 2 fields, field s is pointer to the beginning of the string and field len is length of the string. We then calculate length of the string only once and later reuse saved value.

str structure is quite important because it is widely used in SER (most functions accept str instead of char*).

str Type Declaration

    struct _str{
        char* s;
        int len;
    };

    typedef struct _str str;

The declaration can be found in header file `str.h`.

Because we store string lengths, there is no need to zero terminate them. Some strings in the server are still zero terminated, some are not. Be careful when using functions like `snprintf` that rely on the ending zero. You can print variable of type str this way:

    printf("%.*s", mystring->len, mystring->s);

That ensures that the string will be printed correctly even if there is no zero character at the end.