From 3296ebb98a8403aa50829063fb5c7bbd13790242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 26 Oct 2004 19:42:36 +0000 Subject: [PATCH] When attributes get overwritten, the size may only change with string types, ie. it makes sense to optimize the case when we don't have to move any other item in the small_data region around. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9514 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/Inode.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Inode.cpp b/src/add-ons/kernel/file_systems/bfs/Inode.cpp index 26a22e89c8..0b0ff0cafa 100644 --- a/src/add-ons/kernel/file_systems/bfs/Inode.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Inode.cpp @@ -1,7 +1,7 @@ /* Inode - inode access functions ** ** Initial version by Axel Dörfler, axeld@pinc-software.de -** This file may be used under the terms of the OpenBeOS License. +** This file may be used under the terms of the Haiku License. */ @@ -521,19 +521,24 @@ Inode::AddSmallData(Transaction *transaction, const char *name, uint32 type, last = last->Next(); } - // move the attributes after the current one - small_data *next = item->Next(); - if (!next->IsLast(Node())) - memmove((uint8 *)item + spaceNeeded, next, (uint8 *)last - (uint8 *)next); + // Normally, we can just overwrite the attribute data as the size + // is specified by the type and does not change that often + if (length != item->DataSize()) { + // move the attributes after the current one + small_data *next = item->Next(); + if (!next->IsLast(Node())) + memmove((uint8 *)item + spaceNeeded, next, (uint8 *)last - (uint8 *)next); + + // Move the "last" one to its new location and + // correctly terminate the small_data section + last = (small_data *)((uint8 *)last - ((uint8 *)next - ((uint8 *)item + spaceNeeded))); + if ((uint8 *)last < (uint8 *)Node() + fVolume->BlockSize()) + memset(last, 0, (uint8 *)Node() + fVolume->BlockSize() - (uint8 *)last); - // Move the "last" one to its new location and - // correctly terminate the small_data section - last = (small_data *)((uint8 *)last - ((uint8 *)next - ((uint8 *)item + spaceNeeded))); - if ((uint8 *)last < (uint8 *)Node() + fVolume->BlockSize()) - memset(last, 0, (uint8 *)Node() + fVolume->BlockSize() - (uint8 *)last); + item->data_size = HOST_ENDIAN_TO_BFS_INT16(length); + } item->type = HOST_ENDIAN_TO_BFS_INT32(type); - item->data_size = HOST_ENDIAN_TO_BFS_INT16(length); memcpy(item->Data(), data, length); item->Data()[length] = '\0';