protected FSTClazzInfo writeObjectWithContext(FSTClazzInfo.FSTFieldInfo referencee, Object toWrite, FSTClazzInfo ci) throws IOException {
        int startPosition = 0;
        try {
            if ( toWrite == null ) {
                getCodec().writeTag(NULL, null, 0, toWrite, this);
                return null;
            }
            startPosition = getCodec().getWritten();
            objectWillBeWritten(toWrite, startPosition);
            final Class clazz = toWrite.getClass();
            if ( clazz == String.class ) {
                String[] oneOf = referencee.getOneOf();
                if ( oneOf != null ) {
                    for (int i = 0; i < oneOf.length; i++) {
                        String s = oneOf[i];
                        if ( s.equals(toWrite) ) {
                            getCodec().writeTag(ONE_OF, oneOf, i, toWrite, this);
                            getCodec().writeFByte(i);
                            return null;
                        }
                    }
                }
                // shortpath
                if (! dontShare && writeHandleIfApplicable(toWrite, stringInfo))
                    return stringInfo;
                getCodec().writeTag(STRING, toWrite, 0, toWrite, this);
                getCodec().writeStringUTF((String) toWrite);
                return null;
            } else if ( clazz == Integer.class ) {
                getCodec().writeTag(BIG_INT, null, 0, toWrite, this);
                getCodec().writeFInt(((Integer) toWrite).intValue());
                return null;
            } else if ( clazz == Long.class ) {
                getCodec().writeTag(BIG_LONG, null, 0, toWrite, this);
                getCodec().writeFLong(((Long) toWrite).longValue());
                return null;
            } else if ( clazz == Boolean.class ) {
                getCodec().writeTag(((Boolean) toWrite).booleanValue() ? BIG_BOOLEAN_TRUE : BIG_BOOLEAN_FALSE, null, 0, toWrite, this); return null;
            } else if ( (referencee.getType() != null && referencee.getType().isEnum()) || toWrite instanceof Enum ) {
                return writeEnum(referencee, toWrite);
            }

            FSTClazzInfo serializationInfo = ci == null ? getFstClazzInfo(referencee, clazz) : ci;

            // check for identical / equal objects
            FSTObjectSerializer ser = serializationInfo.getSer();
            if ( ! dontShare && ! referencee.isFlat() && ! serializationInfo.isFlat() && ( ser == null || !ser.alwaysCopy() ) ) {
                if (writeHandleIfApplicable(toWrite, serializationInfo))
                    return serializationInfo;
            }
            if (clazz.isArray()) {
                if (getCodec().writeTag(ARRAY, toWrite, 0, toWrite, this))
                    return serializationInfo; // some codecs handle primitive arrays like an primitive type
                writeArray(referencee, toWrite);
                getCodec().writeArrayEnd();
            } else if ( ser == null ) {
                // default write object wihtout custom serializer
                // handle write replace
                //if ( ! dontShare ) GIT ISSUE 80
            	FSTClazzInfo originalInfo = serializationInfo;
                {	
                    if ( serializationInfo.getWriteReplaceMethod() != null ) {
                        Object replaced = null;
                        try {
                            replaced = serializationInfo.getWriteReplaceMethod().invoke(toWrite);
                        } catch (Exception e) {
                            FSTUtil.<RuntimeException>rethrow(e);
                        }
                        if ( replaced != toWrite ) {
                            toWrite = replaced;
                            serializationInfo = getClassInfoRegistry().getCLInfo(toWrite.getClass(), conf);
                            // fixme: update object map ?
                        }
                    }
                    // clazz uses some JDK special stuff (frequently slow)
                    if ( serializationInfo.useCompatibleMode() && ! serializationInfo.isExternalizable() ) {
                        writeObjectCompatible(referencee, toWrite, serializationInfo);
                        return originalInfo;
                    }
                }

                if (! writeObjectHeader(serializationInfo, referencee, toWrite) ) { // skip in case codec can write object as primitive
                    ser = serializationInfo.getSer();
                    if ( ser == null ) {
                        defaultWriteObject(toWrite, serializationInfo);
                        if ( serializationInfo.isExternalizable() )
                            getCodec().externalEnd(serializationInfo);
                    } else {
                        // handle edge case: there is a serializer registered for replaced class
                        // copied from below :(
                        int pos = getCodec().getWritten();
                        // write object depending on type (custom, externalizable, serializable/java, default)
                        ser.writeObject(this, toWrite, serializationInfo, referencee, pos);
                        getCodec().externalEnd(serializationInfo);
                    }
                }
                return originalInfo;
            } else { // object has custom serializer
                // Object header (nothing written till here)
                if (! writeObjectHeader(serializationInfo, referencee, toWrite) ) { // skip in case code can write object as primitive
                    int pos = getCodec().getWritten();
                    // write object depending on type (custom, externalizable, serializable/java, default)
                    ser.writeObject(this, toWrite, serializationInfo, referencee, pos);
                    getCodec().externalEnd(serializationInfo);
                }
            }
            return serializationInfo;
        } finally {
            objectHasBeenWritten(toWrite, startPosition, getCodec().getWritten());
        }
    }
protected FSTClazzInfo writeObjectWithContext ( FSTClazzInfo . FSTFieldInfo referencee , Object toWrite , FSTClazzInfo ci ) throws IOException { int startPosition = 0 ; try { if ( toWrite == null ) { getCodec ( ) . writeTag ( NULL , null , 0 , toWrite , this ) ; return null ; } startPosition = getCodec ( ) . getWritten ( ) ; objectWillBeWritten ( toWrite , startPosition ) ; final Class clazz = toWrite . getClass ( ) ; if ( clazz == String . class ) { String [ ] oneOf = referencee . getOneOf ( ) ; if ( oneOf != null ) { for ( int i = 0 ; i < oneOf . length ; i ++ ) { String s = oneOf [ i ] ; if ( s . equals ( toWrite ) ) { getCodec ( ) . writeTag ( ONE_OF , oneOf , i , toWrite , this ) ; getCodec ( ) . writeFByte ( i ) ; return null ; } } } if ( ! dontShare && writeHandleIfApplicable ( toWrite , stringInfo ) ) return stringInfo ; getCodec ( ) . writeTag ( STRING , toWrite , 0 , toWrite , this ) ; getCodec ( ) . writeStringUTF ( ( String ) toWrite ) ; return null ; } else if ( clazz == Integer . class ) { getCodec ( ) . writeTag ( BIG_INT , null , 0 , toWrite , this ) ; getCodec ( ) . writeFInt ( ( ( Integer ) toWrite ) . intValue ( ) ) ; return null ; } else if ( clazz == Long . class ) { getCodec ( ) . writeTag ( BIG_LONG , null , 0 , toWrite , this ) ; getCodec ( ) . writeFLong ( ( ( Long ) toWrite ) . longValue ( ) ) ; return null ; } else if ( clazz == Boolean . class ) { getCodec ( ) . writeTag ( ( ( Boolean ) toWrite ) . booleanValue ( ) ? BIG_BOOLEAN_TRUE : BIG_BOOLEAN_FALSE , null , 0 , toWrite , this ) ; return null ; } else if ( ( referencee . getType ( ) != null && referencee . getType ( ) . isEnum ( ) ) || toWrite instanceof Enum ) { return writeEnum ( referencee , toWrite ) ; } FSTClazzInfo serializationInfo = ci == null ? getFstClazzInfo ( referencee , clazz ) : ci ; FSTObjectSerializer ser = serializationInfo . getSer ( ) ; if ( ! dontShare && ! referencee . isFlat ( ) && ! serializationInfo . isFlat ( ) && ( ser == null || ! ser . alwaysCopy ( ) ) ) { if ( writeHandleIfApplicable ( toWrite , serializationInfo ) ) return serializationInfo ; } if ( clazz . isArray ( ) ) { if ( getCodec ( ) . writeTag ( ARRAY , toWrite , 0 , toWrite , this ) ) return serializationInfo ; writeArray ( referencee , toWrite ) ; getCodec ( ) . writeArrayEnd ( ) ; } else if ( ser == null ) { FSTClazzInfo originalInfo = serializationInfo ; { if ( serializationInfo . getWriteReplaceMethod ( ) != null ) { Object replaced = null ; try { replaced = serializationInfo . getWriteReplaceMethod ( ) . invoke ( toWrite ) ; } catch ( Exception e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } if ( replaced != toWrite ) { toWrite = replaced ; serializationInfo = getClassInfoRegistry ( ) . getCLInfo ( toWrite . getClass ( ) , conf ) ; } } if ( serializationInfo . useCompatibleMode ( ) && ! serializationInfo . isExternalizable ( ) ) { writeObjectCompatible ( referencee , toWrite , serializationInfo ) ; return originalInfo ; } } if ( ! writeObjectHeader ( serializationInfo , referencee , toWrite ) ) { ser = serializationInfo . getSer ( ) ; if ( ser == null ) { defaultWriteObject ( toWrite , serializationInfo ) ; if ( serializationInfo . isExternalizable ( ) ) getCodec ( ) . externalEnd ( serializationInfo ) ; } else { int pos = getCodec ( ) . getWritten ( ) ; ser . writeObject ( this , toWrite , serializationInfo , referencee , pos ) ; getCodec ( ) . externalEnd ( serializationInfo ) ; } } return originalInfo ; } else { if ( ! writeObjectHeader ( serializationInfo , referencee , toWrite ) ) { int pos = getCodec ( ) . getWritten ( ) ; ser . writeObject ( this , toWrite , serializationInfo , referencee , pos ) ; getCodec ( ) . externalEnd ( serializationInfo ) ; } } return serializationInfo ; } finally { objectHasBeenWritten ( toWrite , startPosition , getCodec ( ) . getWritten ( ) ) ; } }
splitting this slows down ...