[haiku-commits] Re: haiku: hrev52979 - src/system/kernel headers/private/shared src/system/kernel/debug src/system/kernel/messaging src/system/kernel/slab

  • From: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 9 Mar 2019 19:47:13 +0100

Am 09/03/2019 um 18:09 schrieb waddlesplash:

@@ -1338,8 +1339,8 @@ SystemProfiler::_AllocateBuffer(size_t size, int event, 
int cpu, int count)
                // Buffer is wrapped or needs wrapping.
                if (end < fBufferCapacity) {
                        // not wrapped yet, but needed
-                       system_profiler_event_header* header
-                               = (system_profiler_event_header*)(fBufferBase + 
end);
+                       BytePointer<system_profiler_event_header> header(
+                               fBufferBase + end);

While I welcome the class itself, I don't see much reason to use it in this case.

@@ -199,8 +200,7 @@ MessagingArea::AllocateCommand(uint32 commandWhat, int32 
dataSize,
        }
// init the command
-       messaging_command *command
-               = (messaging_command*)((char*)fHeader + commandOffset);
+       BytePointer<messaging_command> command((char*)fHeader + commandOffset);

And if it is used like this, it does complicate the code, not simplify it.
Can't it be used like this instead:
        BytePointer<messaging_command> command(fHeader);
        command += commandOffset
?

-       messaging_command*command = (messaging_command*)((char*)fHeader + 
offset);
+       BytePointer<messaging_command> command((char*)fHeader + offset);

Almost the same here.

  static inline object_link*
  object_to_link(void* object, size_t objectSize)
  {
-       return (object_link*)(((uint8*)object)
+       BytePointer<object_link> pointer((uint8*)object
                + (objectSize - sizeof(object_link)));
+       return &pointer;

Definitely the same here. If it complicates the code, don't use it.

  static inline slab *
  slab_in_pages(const void *pages, size_t slab_size)
  {
-       return (slab *)(((uint8 *)pages) + slab_size - sizeof(slab));
+       BytePointer<slab> pointer(((uint8 *)pages) + slab_size - sizeof(slab));
+       return &pointer;

And here, too:
        BytePointer<slab> pointer(pages);
        pointer += slab_size - sizeof(slab));

would improve the readability.

Bye,
   Axel.

Other related posts: