Menu

#15 manual code inlining preprocessor

open
nobody
None
5
2007-06-29
2007-06-29
Anonymous
No

A very straight forward approach to have a way for code/method inlining from the same source (without #include). The sample:

==============
public class AClass
{
static boolean bool1 = false;
static boolean bool2 = false;

static void methodCalledMultipleTimes()
{
//#inlineas methodCalledMultipleTimes
// Lots of code...
bool1 = bool2;
//#endinline
}

static void methodA()
{
methodCalledMultipleTimes();
//#inlinecode methodCalledMultipleTimes
}

static void methodB()
{
methodCalledMultipleTimes();
//#inlinecode methodCalledMultipleTimes
}
}
============

would end up like:

===========
public class AClass
{
static boolean bool1 = false;
static boolean bool2 = false;

static void methodCalledMultipleTimes()
{
}

static void methodA()
{
methodCalledMultipleTimes();
// Lots of code...
bool1 = bool2;
}

static void methodB()
{
methodCalledMultipleTimes();
// Lots of code...
bool1 = bool2;
}
}
===========

After that, obfuscator should take care of the empty methods being called. Yes, this approach would not be as general, probably. Programmer can very easily mess up here. And, also, careful should be if the method returns something or uses inner-fields. But, that is why I would call it "manual code inlining" :D

Discussion