Commit 13fa6bbe authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Add clang-format

parent 6c942fb0
No related merge requests found
Showing with 37 additions and 16 deletions
+37 -16
---
# We'll use defaults from the Google style, but with 4 columns indentation.
BasedOnStyle: Google
# Never allow single-line functions
AllowShortFunctionsOnASingleLine: None
# Put "else" on a new line
BreakBeforeBraces: Custom
BraceWrapping:
BeforeElse: true
# Allow lines up to 90 characters
ColumnLimit: 90
# Indent each block by 4 spaces
IndentWidth: 4
TabWidth: 4
# Require 1 space before a comment on the same line
SpacesBeforeTrailingComments: 1
# Put a space after a cast, e.g. `(void) arg;`
SpaceAfterCStyleCast: true
---
#!/bin/bash
if loc="$(type -p "clang-format")" && [[ -x $loc ]]; then
for name in $(git diff --cached --name-only --diff-filter=ACM); do
if echo $name | grep -Eq "\.[ch]$"; then
echo "Formatting ${name}..."
clang-format -i $name
fi
done
else
echo "You do not have clang-format installed; so, we were unable to unify the formatting in your files."
fi
......@@ -6,8 +6,8 @@
#include <stdint.h>
#include "mm.h"
#include "memlib.h"
#include "mm.h"
/** The required alignment of heap payloads */
const size_t ALIGNMENT = 2 * sizeof(size_t);
......@@ -54,11 +54,8 @@ static bool is_allocated(block_t *block) {
*/
static block_t *find_fit(size_t size) {
// Traverse the blocks in the heap using the implicit list
for (
block_t *curr = mm_heap_first;
mm_heap_last != NULL && curr <= mm_heap_last;
curr = (void *) curr + get_size(curr)
) {
for (block_t *curr = mm_heap_first; mm_heap_last != NULL && curr <= mm_heap_last;
curr = (void *) curr + get_size(curr)) {
// If the block is free and large enough for the allocation, return it
if (!is_allocated(curr) && get_size(curr) >= size) {
return curr;
......@@ -72,7 +69,6 @@ static block_t *block_from_payload(void *ptr) {
return ptr - offsetof(block_t, payload);
}
/**
* mm_init - Initializes the allocator state
*/
......@@ -157,5 +153,4 @@ void *mm_calloc(size_t nmemb, size_t size) {
* mm_checkheap - So simple, it doesn't need a checker!
*/
void mm_checkheap(void) {
}
......@@ -7,8 +7,8 @@
#include <stdint.h>
#include "mm.h"
#include "memlib.h"
#include "mm.h"
/** The required alignment of heap payloads */
const size_t ALIGNMENT = 2 * sizeof(size_t);
......@@ -55,11 +55,8 @@ static bool is_allocated(block_t *block) {
*/
static block_t *find_fit(size_t size) {
// Traverse the blocks in the heap using the implicit list
for (
block_t *curr = mm_heap_first;
mm_heap_last != NULL && curr <= mm_heap_last;
curr = (void *) curr + get_size(curr)
) {
for (block_t *curr = mm_heap_first; mm_heap_last != NULL && curr <= mm_heap_last;
curr = (void *) curr + get_size(curr)) {
// If the block is free and large enough for the allocation, return it
if (!is_allocated(curr) && get_size(curr) >= size) {
return curr;
......@@ -73,7 +70,6 @@ static block_t *block_from_payload(void *ptr) {
return ptr - offsetof(block_t, payload);
}
/**
* mm_init - Initializes the allocator state
*/
......@@ -158,5 +154,4 @@ void *mm_calloc(size_t nmemb, size_t size) {
* mm_checkheap - So simple, it doesn't need a checker!
*/
void mm_checkheap(void) {
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment