9

27-Jul-2011: Strings in Oracle RDBMS network layer

 3 years ago
source link: https://yurichev.com/blog/64/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Strings in Oracle RDBMS network layer

27-Jul-2011: Strings in Oracle RDBMS network layer

Not sure if it's worth blogging...

All strings in Oracle RDBMS network layer are usual C-strings terminated by zero byte, but often, string length is also passing as a separate function argument. This makes some things much faster.

  • strlen() is not necessary anymore - just take string length you already have.
  • strcat() do not need to calculate string lengths.
  • strcmp() against const string is working much faster:

Instead of:

if (strcmp (s, "STRING")) ...

We have (we first check 's' string len against "STRING" length, if it doesn't equal, we may not compare each byte):

if (s_len==6)
    if (strcmp (s, "STRING"))..

Another example is:

if (strcmp (s, "ASD"))...
if (strcmp (s, "DEF"))...

if (strcmp (s, "ASD1"))...
if (strcmp (s, "ORCL"))...

Instead, we can write:

void f(char* s, int s_len)
{

if (s_len==3)
{
... check s against all 3-char strings here: ASD, DEF
}
else
if (s_len==4)
{
... check s against all 4-char strings here: ASD1, ORCL
}
else
{
... check the rest
}

... which is much faster, of course.

All strings are still C-strings with zero byte at the end, so they are all can be used as argument to any C standard library function.


→ [list of blog posts]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK