Hot answers tagged

5

General Observations It would be much easier to review this code if there was either a unit test or example code to see how this code should be used. It also isn't clear why the code deletes the key value pair within the function getValueFor(). The function name does not indicate that it is deleting the pair as well as getting the value for the key. Error ...


5

Major remark of the code as whole: for some reason you write the unreadable version of array access *(arr+i) all over the place. Don't do that! This makes your code look needlessly obscure and hard to read. Instead use the much more readable arr[i]. Your compare is just a naive implementation of strchr. It would be much more efficient to use strchr. Don't ...


3

public class PacketBuilder { ... public class PacketParser { This I actually like very much, a clear distinction between objects that encode and decode. Or build and parse if you like. First lets start with naming / terminology. AES is a block cipher, a method for encryption and decryption. When we are talking about encoding we should be talking about e.g....


3

Naming C reserves identifiers beginning with _ followed by any letter for the implementation, so they should not be defined by user programs. I can't quite remember whether leading _ is permitted in struct tags (that's a different namespace to object and function names), because it's simpler to just avoid using leading _ anywhere, and never have to know the ...


3

compare is a dubious name. The purpose of the function is to tell whether parse string contains a character. Consider bool contains(char * str, char ch); The special case does not check for a possible overflow. temp_matrix_length could reach temp_matrix_size by the time it is executed. I do not endorse a pointer notation here. string[i] is easier to read ...


1

In addition to the other answers: strpbrk or strcspn are useful for finding the next delimiter in a string. strspn can be used to find the next character that isn't a delimiter in a string. So given a char const* str as input, we could do something like: while (*str) { char const* end = strpbrk(str, delimiters); if (!end) end = strchr(str, '\0'); /*...


1

InputFile doesn't appear to be a file — a better name might be Statistics. usize is conventionally used for indexes and sizes instead of u32. Don't take an argument by &String. Since the algorithm works for not only files but other streams of characters as well, consider taking a BufRead argument. Reading the whole file into memory isn't efficient — an ...


1

I don't think I understand the point of declaring a class if you aren't going to write any methods in it. I mean why go the expense of declaring a class just to store some variables outside of the global scope. Assuming this class can never populate its properties without parsing a document, so it make sense to have its constructor initiate the file reading ...


1

Aside from other suggestions which make sense, one simple thing to try is to use Aalto-xml parser from: https://github.com/FasterXML/aalto-xml it implements Stax API (as well as Stax2 extension, SAX); and as long as you do not need full DTD handling (which I suspect you don't) has the feature set you need. For common read use cases I think it can be 30-40% ...


Only top voted, non community-wiki answers of a minimum length are eligible